Docker Swarm bind 数据持久化

Docker Swarm bind 数据持久化

  • bind:主要将工作节点宿主级文件或目录,同步挂载到容器中。

环境:

  • 系统:Centos 7.4 x64
  • 应用版本:Docker 18.09.0
  • 管理节点:192.168.1.79
  • 工作节点:192.168.1.78
  • 工作节点:192.168.1.77

一、两种宿主级挂载方式

管理节点:读写挂载

docker service create \
--mount type=bind,src=<HOST-PATH>,dst=<CONTAINER-PATH> \
--name myservice \
<IMAGE>

管理节点:只读挂载

docker service create \
--mount type=bind,src=<HOST-PATH>,dst=<CONTAINER-PATH>,readonly \
--name myservice \
<IMAGE>

二、创建bind 数据持久化

1、管理节点:创建服务并添加bind读写挂载

docker service create \
--mount type=bind,src=/etc,dst=/data \
--name test01 \
busybox ping www.baidu.com
# 创建服务
docker service create \
# 创建数据卷 type=bind,src=宿主目录,dst=容器目录
--mount type=bind,src=/etc,dst=/data \
# 服务名
--name test01 \
# 镜像
busybox
# 容器内执行指令
ping www.baidu.com
命令解析
docker service inspect test02
 "Mounts": [
                        {
                            "Type": "bind",
                            "Source": "/etc",
                            "Target": "/data"
                        }
                    ]
查看服务详细信息,截取挂载节点详细信息

2、工作节点:进入容器测试挂载目录

# 进入容器
docker exec -it e4d7e2d88cab sh
# 测试目录与/etc一致
/ # cd /data
/data # ls
....

 

posted @ 2018-11-10 11:31  kevin.Xiang  阅读(953)  评论(0编辑  收藏  举报