是什么?能干嘛?
- 容器的持久化和同步操作
- 容器间继承、共享数据,容器中产生的数据同步到本地
- 目录挂载,容器的目录,挂载到Linux上面
数据卷
- 命令
docker run -it -v 主机目录:容器目录:权限
ro readonly #只读
rw readwrite #可读可写
# 一旦设置了容器的权限,容器对我们挂载的内容就有限定了
- 直接命令添加
docker run -it -v /data/nginx/data:/data nginx
- 只读权限
docker run -it -v /data/nginx/data:/data:ro nginx
# 这种情况下/data 目录就只能从内部改变,不能从外部改变
- Dockerfile添加
cat > Dockerfile <<EOF
FROM centos
VOLUME ["/data0","/data1"]
CMD echo "finished,-----success"
CMD /bin/bash
EOF
docker build -f /mydocker/Dockerfile -t leoiceo/centos:1.0 .
启动后默认会挂载容器卷
"Mounts": [
{
"Type": "volume",
"Name": "5f97720950c327cafb80cd87ab0531122cd1895e4662448a5a05377720ca59e2",
"Source": "/var/lib/docker/volumes/5f97720950c327cafb80cd87ab0531122cd1895e4662448a5a05377720ca59e2/_data",
"Destination": "/data0",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "volume",
"Name": "4667ae2597114426e41f98d8fda7104ee2d881236aa8423826df8f6956662b08",
"Source": "/var/lib/docker/volumes/4667ae2597114426e41f98d8fda7104ee2d881236aa8423826df8f6956662b08/_data",
"Destination": "/data1",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],