通过容器/模板创建镜像

通过容器创建镜像

进入启动的容器:

[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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值