DockerFile就是用来构建镜像的。
#测试
#1.创建1个DockerFile,内容如下:
FROM centos
VOLUME {"volume01","volume02"}
CMD echo "-----end-----"
CMD /bin/bash
#2.构建
docker build -f docker-file1 -t mn/centos:1.0 .
[root@iz2ze2aj5v2nx1t6jk26cfz ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mn/centos 1.0 b692cf436876 3 hours ago 231MB
tomcat latest b0e0b0a92cf9 11 days ago 680MB
mysql 5.7 938b57d64674 2 weeks ago 448MB
[root@iz2ze2aj5v2nx1t6jk26cfz ~]# docker run -it b692cf436876 /bin/bash
[root@6f4563b3748b /]#
#3.在容器里创建一个test.txt文件
#4.退出容器
#5.docker inspect 容器ID 查看容器详情
#6.可看到挂载信息
#7.查看刚创建的文件是否同步过来
[root@iz2ze2aj5v2nx1t6jk26cfz docker-test-volume]# cd /var/lib/docker/volumes/3b6145e551088e4868c0c1bfc80bc4404121b488a5ec09e2349d2126b1399694/_data
[root@iz2ze2aj5v2nx1t6jk26cfz _data]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 2 21:02 test.txt
[root@iz2ze2aj5v2nx1t6jk26cfz _data]#
备注:文章来源于视频: 遇见狂神说(Ps:狂神的课真的特别好~)