通过容器创建镜像
进入启动的容器:
[root@zhangfei ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73442367c1f5 centos "/bin/bash" 41 minutes ago Up 41 minutes heuristic_brattain
[root@zhangfei ~]# docker exec -it 734423 bash
[root@73442367c1f5 /]# yum install -y net-tools
[root@73442367c1f5 /]# exit
exit
将容器做成镜像:
[root@zhangfei ~]# docker commit -m "install net-tools" -a "zhangfei" 73442367c1f5 centos_with_net
sha256:3d6ce9135f1b28cf89d9387e6b861540f66865fe14e717f04fef692aba814702
[root@zhangfei ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_with_net latest 3d6ce9135f1b 23 seconds ago 277MB
aminglinux_centos latest d123f4e55e12 11 days ago 197MB
centos latest d123f4e55e12 11 days ago 197MB
[root@zhangfei ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
947c894ef76a centos_with_net "bash" 2 minutes ago Up 2 minutes musing_bhaskara
73442367c1f5 centos "/bin/bash" About an hour ago Up About an hour heuristic_brattain
[root@zhangfei ~]# docker exec -it musing_bhaskara bash
通过模板创建镜像
[root@zhangfei ~]# wget https://download.openvz.org/template/precreated/centos-6-x86-minimal.tar.gz
把模板导成镜像:
[root@localhost ~]# cat centos-6-x86-minimal.tar.gz |docker import - centos6
sha256:6fab0d69e1b319b7ff2797f8061fbb44323fca3627c0e3e278038c71e9471eef
用镜像启动容器:
[root@localhost ~]# docker run -itd centos6 bash
6a30c38e5dcd9cbe416bfd34765d822fad87e60b0fcf384597b8c3e4db289fe8
进入容器:
[root@localhost ~]# docker exec -it 6a30c38e5dcd9c bash
把现有镜像导出为文件:
[root@localhost ~]# docker save -o centos7_with_nettool.tar centos_with_net
用文件恢复本地镜像:
[root@localhost ~]# docker load --input centos7_with_nettool.tar
或者
[root@localhost ~]# docker load< centos7_with_nettool.tar