大家好,我们今天分享使用Dockerfile来实现数据卷的挂载
首先呢,要了解一下什么是Dockerfile
Dockerfile就是 一个可以用来构建镜像的文件,可以理解为一个脚本文件
可以通过这个脚本文件自定义生成一个我们想要的镜像,镜像都是一层一层的,里面的每一条命令就是一层
创建一个目录
[root@localhost home]# mkdir docker-vl2
编辑这样这样的一个文件
root@localhost docker-vl2]# vim dockerfile01
FROM centos
VOLUME ["volume01","volume02"]
CMD echo "------end-----"
CMD /bin/bash
~
~
~
~
保存退出:
构建成新的镜像,注意看shuaige/centos:2.0有一个小点
[root@localhost docker-vl2]# docker build -f dockerfile01 -t shuaige/centos:2.0 .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM centos
---> 5d0da3dc9764
Step 2/4 : VOLUME ["volume01","volume02"]
---> Running in 96445950bbef
Removing intermediate container 96445950bbef
---> ffcf0eb8973b
Step 3/4 : CMD echo "------end-----"
---> Running in a4fa6fce633b
Removing intermediate container a4fa6fce633b
---> 5416582373e0
Step 4/4 : CMD /bin/bash
---> Running in 7d7df79e0b36
Removing intermediate container 7d7df79e0b36
---> d8e0f44b8da3
Successfully built d8e0f44b8da3
Successfully tagged shuaige/centos:2.0
看这个过程,一共有4步,对应着我们刚刚写的dockerfile 文件
也是一层一层的
查看镜像