制作Docker镜像的方式一般有两种:手工制作和通过Dockerfile制作,此次讲解的是手工制作docker镜像。
一、手动制作镜像:
- 用centos镜像启动容器:
[[email protected]_0_12_centos ~]# docker run -it centos bash
2. 在容器中安装网络管理工具:
[[email protected] /]# yum -y install net-tools iproute
3. 将修改后的容器保存为镜像:
先按ctrl+p+q后台运行容器,退出系统页面
[[email protected]_0_12_centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfb0d2f70053 centos "bash" 4 minutes ago Up 4 minutes distracted_ramanujan [[email protected]_0_12_centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfb0d2f70053 centos "bash" 4 minutes ago Up 4 minutes distracted_ramanujan [[email protected]_0_12_centos ~]# docker commit dfb0 centos:test //dfb0是容器ID,centos是保存的镜像名,test是tag sha256:35fcec794c886d63d2ab74ec11c4f95ab784366a3bd14f97971737bd9578210e [[email protected]_0_12_centos ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos test 35fcec794c88 About a minute ago 280.1 MB
4. 通过新镜像生成容器:
[[email protected]_0_12_centos ~]# docker run -i -t centos:test [[email protected] /]#
时间: 2024-10-07 07:05:57