3.5构建自己的镜像
在本节中,我们基于一个centos base image制作一个安装有vim的镜像。
镜像制作支持两种方式:
基于容器构建镜像
基于Dockerfile构建镜像(推荐)
前提条件
主机已具有centos镜像,如主机不满足条件,可使用如下命令拉取镜像
[root@master hello-world]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
d8d02d457314: Pull complete
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:latest
[root@master hello-world]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 67fa590cfc1c 6 days ago 202MB基于容器构建镜像
1.以交互的方式运行一个centos容器
2.在centos容器中安装vim,验证vim功能,并退出容器
3.构建镜像并查看生成的镜像
扩展:产看镜像层次可以使用:docker history [OPTIONS] IMAGE
基于Dockerfile构建镜像
1.新建工作目录并打开
2.新建Dockerfile文件
Dockerfile文件内容如下:
3.构建镜像并查看生成的镜像
Last updated
Was this helpful?