docker数据卷容器

数据卷容器

数据卷容器功能是可以让数据在多个docker容器之间共享,即可以让B容器访问A容器的内容,而容器C也可以访问A容器的内容,即先要创建一个后台运行的容器作为server,用于卷提供,这个卷可以为其他容器提供数据存储服务,其他使用此卷的容器作为client端。

日志输出使用
静态文件使用
配置文件使用
多个容器间目录或文件共享

创建数据卷容器

#宿主机目录必须有nginx数据否则无法启动
mkdir /data/nginx-html
mkdir /data/logs/nginx
mkdir /data/conf/nginx
#例
[root@localhost nginx-html]# ls
index.html
[root@localhost nginx-html]# pwd
/data/nginx-html
[root@localhost nginx]# ls
nginx.conf
[root@localhost nginx]# pwd
/data/conf/nginx

#创建
docker run -it -d -v /data/nginx-html:/usr/local/nginx/html -v /data/logs/nginx:/usr/local/nginx/logs -v /data/conf/nginx/nginx.conf:/usr/local/nginx/conf/nginx.conf --name volume-server  nginx-base:1.16.1

其他容器挂载数据卷容器

docker run -it -d --volumes-from volume-server -p 80:80 --name web1  nginx-base:1.16.1

访问

在这里插入图片描述

注意事项

1.当web1使用了volume-server容器的情况下,删除已经挂载volume-server容器,web1不受影响可以继续访问使用。
2.当web1使用了volume-server容器的情况下,删除已经挂载volume-server容器,web1停止启动和重启都不会影响使用。
3.但是新创建的web2容器就不可以使用volume-server容器了
4.重新创建已经删除的volume-server容器,web1也不受影响,其他容器也可以继续使用volume-server容器了。
5.web1使用olume-server容器会继承挂载到volume-server容器宿主机目录的权限。
6.volume-server容器关闭之后,依然可以创建新的容器。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值