【docker】mount+bind+swarm管理数据

1.bind+mount 方式管理数据。

bind mount 模式:将宿主机某个目录映射到docker容器,很适合于网站,
同时把宿主机的这个目录作为git版本目录,每次update 代码的时候,容器就会更新。

2.创建数据目录。

在 mananger、worker01、worker02 上创建web 网站目录:
mkdir -p /data/web
echo "outside website" >> /data/web/index.html

3.将本地的

192.168.1.7:
docker service create --replicas 3 --mount type=bind,src=/data/web,dst=/usr/share/nginx/html -p 8012:80 \
--name mynginx3 192.168.1.11:443/myharbor/nginx:latest

[root@es1 data]# docker service create --replicas 3 --mount type=bind,src=/data/web,dst=/usr/share/nginx/html -p 8012:80 \
> --name mynginx3 192.168.1.11:443/myharbor/nginx:latest
mvjwtb0rixsrilnyglq0gvf72
overall progress: 3 out of 3 tasks 
1/3: running   
2/3: running   
3/3: running   
verify: Service converged 



docker volume ls  --会自动创建nginxdata; 
docker service ps -f 'desired-state=running' mynginx3   --检查running状态的服务。
docker service rm fgeduweb8012

[root@es1 data]# docker service ps -f 'desired-state=running' mynginx3 
ID             NAME         IMAGE                                    NODE      DESIRED STATE   CURRENT STATE           ERROR     PORTS
tmsrh710erch   mynginx3.1   192.168.1.11:443/myharbor/nginx:latest   es1       Running         Running 2 minutes ago             
glaonlq28tr1   mynginx3.2   192.168.1.11:443/myharbor/nginx:latest   es3       Running         Running 2 minutes ago             
x6fokwgpi5ww   mynginx3.3   192.168.1.11:443/myharbor/nginx:latest   es2       Running         Running 2 minutes ago   


这两种挂载方式在使用上,应用上几乎没有区别。

4.测试打开:

curl http://192.168.1.7:8012/index.html  
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx3
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx2
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx1
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx3
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx2
[root@es1 web]# curl http://192.168.1.7:8012/index.html 
I'm nginx,mynginx1

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值