创建Dockerfile文件
mkdir -p /mydocker/Dockerfile vim Dockerfile FROM centos:6.8 # 创建数据卷 VOLUME ["/dataVolumeContainer1", "/dataVolumeContainer2"] CMD echo "finished......" CMD /bin/bash
构建镜像
docker build -f /mydocker/Dockerfile -t bingjjfly/centos:1.0 .
创建容器
# 不指定宿主机目录 docker run -it bingjjfly/centos:1.0 /bin/bash # 指定宿主机目录 docker run -it -v /host1:/dataVolumeContainer1 -v /host2:/dataVolumeContainer2 bingjjfly/centos:1.0 /bin/bash
查看数据卷
ls / bin dataVolumeContainer2 etc lib lost+found mnt proc sbin srv tmp var dataVolumeContainer1 dev home lib64 media opt root selinux sys usr
查看容器信息
docker inspect d0260cda3da5 "Volumes": { "/dataVolumeContainer1": "/var/lib/docker/volumes/77400cdc2df0fa3b8a0241570e03945ac1cdb8eae372cf3978ef4ac1062b2be9/_data", "/dataVolumeContainer2": "/var/lib/docker/volumes/e69cd5cfd2d296e8777edcdd04ed06b38ec3df73fbdf8c3a4e900eff5a2ca148/_data" }, "VolumesRW": { "/dataVolumeContainer1": true, "/dataVolumeContainer2": true }