数据卷容器
数据卷容器功能是可以让数据在多个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容器关闭之后,依然可以创建新的容器。