操作环境
[root@docker-node-1 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
CentOS Linux release 7.4.1708 (Core)
[root@docker-node-1 ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 06:38:28 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 06:38:28 2017
OS/Arch: linux/amd64
Experimental: false
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 06:38:28 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 092cba3
Built: Wed Feb 8 06:38:28 2017
OS/Arch: linux/amd64
Experimental: false
注意:要使用docker plugin,API Version必须是1.25以上
操作步骤
1.部署BlockBridge Stroage Controller Container
[root@docker-node-1 ~]# curl -sSL https://get.blockbridge.com/container | sh
latest: Pulling from blockbridge/simulator-up
Digest: sha256:239332e49df6d0006c9d1a1cd82fee73f02015fc123c30e61b5e4088114dfa20
Status: Image is up to date for blockbridge/simulator-up:latest
Pulling blockbridge-simulator-converged (blockbridge/simulator:latest)...
latest: Pulling from blockbridge/simulator
a2392627bec4: Pull complete
e50431e8a0b3: Pull complete
d915d581141d: Pull complete
a430ee89ece6: Pull complete
076100e6c581: Pull complete
488bf3979b2a: Pull complete
86acba7f73bc: Pull complete
46d3d3d13eca: Pull complete
2233882ff390: Pull complete
5a53d4e78a35: Pull complete
53d63163212f: Pull complete
ac1513e16138: Pull complete
e0ed5f301886: Pull complete
Digest: sha256:e558c413fafd2571be9716c939e750c69aa7e5d5cd216e1eeb500e95b95b1be6
Status: Downloaded newer image for blockbridge/simulator:latest
Creating network "blockbridgesimulator_default" with the default driver
Creating volume "blockbridgesimulator_bb_data" with default driver
Creating bbsim-converged
Waiting for container to boot...........................................
=================================================================================
Blockbridge Storage Container 3.1.1-3925.1 (c32471b6-a1c2-4c62-b466-08aa2046afef)
Mode: converged
Generated Credentials (may not reflect current system state)
System admin API token: 1/oaqFOqFFs6HGkXumj2tH2WRPkg6OgCcVLJhF8MmcH42xqoU6oUWy4A
System admin username: system
System admin password: 53187770f46d19dfdd3e446b1e34fa47
Default user username: default
Default user password: 5e73ab9e1e0bb51b75ee8b2ae1d243dc
Volume plugin API token: 1/7o2AbZ0QmcTztRAg4ooX6NenoEMfFI96NBhv+lG/OgXOjYBtnRCYhQ
=================================================================================
2.安装docker plugin
# docker plugin install --alias block blockbridge/volume-plugin \
> BLOCKBRIDGE_API_HOST="docker-node-1" BLOCKBRIDGE_API_KEY="1/7o2AbZ0QmcTztRAg4ooX6NenoEMfFI96NBhv+lG/OgXOjYBtnRCYhQ"
Plugin "blockbridge/volume-plugin" is requesting the following privileges:
- network: [host]
- mount: [/dev]
- mount: [/sys]
- mount: [/var/run]
- mount: [/lib/modules]
- allow-all-devices: [true]
- capabilities: [CAP_IPC_LOCK CAP_IPC_OWNER CAP_NET_ADMIN CAP_SYS_ADMIN CAP_MKNOD CAP_SYS_MODULE]
Do you grant the above permissions? [y/N] y
latest: Pulling from blockbridge/volume-plugin
3.查看plugin
[root@docker-node-1 ~]# docker plugin ls
ID NAME DESCRIPTION ENABLED
f2a95b8999b8 block:latest Blockbridge Volume Plugin true
4.创建driver为blockbridge的volume
[root@docker-node-1 ~]# docker volume create --name blockbrige-1 --driver=block
blockbrige-1
[root@docker-node-1 ~]# docker volume inspect blockbrige-1
[
{
"Driver": "block:latest",
"Labels": {},
"Mountpoint": "/var/lib/docker/plugins/f2a95b8999b82f7f2b99cac2a090a958c41c43bcd56f28dbaa08e0f0cc8ff353/rootfs",
"Name": "blockbrige-1",
"Options": {},
"Scope": "global",
"Status": {
"capacity": "1GiB",
"name": "blockbrige-1",
"user": "default"
}
}
]
[root@docker-node-1 ~]# docker volume create --name blockbridge-2 --driver=block --opt capacity=4GiB
blockbridge-2
[root@docker-node-1 ~]# docker volume inspect blockbridge-2
[
{
"Driver": "block:latest",
"Labels": {},
"Mountpoint": "/var/lib/docker/plugins/f2a95b8999b82f7f2b99cac2a090a958c41c43bcd56f28dbaa08e0f0cc8ff353/rootfs",
"Name": "blockbridge-2",
"Options": {
"capacity": "4GiB"
},
"Scope": "global",
"Status": {
"capacity": "4GiB",
"name": "blockbridge-2",
"user": "default"
}
}
]
如果只想查看driver为block的volume
[root@docker-node-1 ~]# docker volume ls -f driver=block
DRIVER VOLUME NAME
block:latest blockbridge-2
block:latest blockbrige-1
block:latest data
block:latest data1
4.启动driver为block的container
[root@docker-node-1 ~]# docker run --name blockcontainer-1 --volume-driver block -v data2:/data -d -it centos
b03ed4a1c5bcaa05db2cdd66af40dd5b8a726d9d415495230ba98d02c96cd41a
进入container,可以看见/data目录下挂载的data2默认是1GiB
[root@docker-node-1 ~]# docker attach blockcontainer-1
[root@b03ed4a1c5bc /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/docker-253:1-1073870859-f2792197a387dabbbd6550258ca4204669f3a8385ecc23e1bc48c51ed7a03360 10G 247M 9.8G 3% /
tmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/blockbridge/data2/DSK1969394C40626500 1022M 33M 990M 4% /data
/dev/mapper/centos-root 905G 4.6G 901G 1% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 7.8G 0 7.8G 0% /sys/firmware
如果想data目录容量大一点,可以先创建volume
[root@docker-node-1 ~]# docker volume create --name data3 --driver=block --opt capacity=10Gib
data3
[root@docker-node-1 ~]# docker volume inspect data3
[
{
"Driver": "block:latest",
"Labels": {},
"Mountpoint": "/bb/mnt/data3",
"Name": "data3",
"Options": {
"capacity": "10Gib"
},
"Scope": "global",
"Status": {
"capacity": "10Gib",
"name": "data3",
"user": "default"
}
}
]
启动新container
[root@docker-node-1 ~]# docker attach blockcontainer-2
[root@577c32a22130 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/docker-253:1-1073870859-c1c9f44cc5ae5b52dd1d1f952f4412bd9fb95e73602ff85ca5cd541da07f90bd 10G 247M 9.8G 3% /
tmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/blockbridge/data3/DSK1969B94C40626530 10G 33M 10G 1% /data
/dev/mapper/centos-root 905G 4.6G 901G 1% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs