docker(8)镜像制作(容器转为镜像)

Docker镜像制作方式:

  1. 容器转为镜像
  2. dockerfile

容器转为镜像(不常用)

# 将容器转为镜像
docker commit 容器id 镜像名称:版本号

# 将镜像转为压缩文件进行传输
docker save -o 压缩文件名称 镜像名称:版本号

# 将压缩文件还原为镜像
docker load -i 压缩文件名称

在这里插入图片描述
控制台执行:

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                                                    COMMAND             CREATED             STATUS                       PORTS               NAMES
1f3e008ee9a3        centos                                                   "/bin/bash"         59 minutes ago      Exited (0) 12 minutes ago                         c2
41b97000dde8        centos                                                   "/bin/bash"         About an hour ago   Exited (0) 54 minutes ago                         c1
7048bbaeb3b5        centos                                                   "/bin/bash"         About an hour ago   Exited (127) 12 minutes ago                       c3
[root@localhost ~]# docker commit 41b97000dde8 test_centos:1.0
sha256:3702cc1d86027b48e4d8aca97ac9a623d745f414a3d93ee4f020737691b0babc
[root@localhost ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
test_centos                                              1.0                 3702cc1d8602        13 seconds ago      231 MB
hello-world                                              latest              feb5d9fea6a5        2 months ago        13.3 kB
centos                                                   latest              5d0da3dc9764        3 months ago        231 MB
[root@localhost ~]# docker save -o test_centos.tar test_centos:1.0
[root@localhost ~]# ls
anaconda-ks.cfg  data  initial-setup-ks.cfg  test_centos.tar  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@localhost ~]# docker rmi 3702cc1d8602 
Untagged: test_centos:1.0
Deleted: sha256:3702cc1d86027b48e4d8aca97ac9a623d745f414a3d93ee4f020737691b0babc
Deleted: sha256:962a2b659fadddb7fd18b7df587ae44cc3584cbc9ed0ddf6710e3496035af5ac
[root@localhost ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
docker.io/tomcat                                         latest              24207ccc9cce        12 days ago         680 MB
mysql                                                    5.7                 738e7101490b        2 weeks ago         448 MB
hello-world                                              latest              feb5d9fea6a5        2 months ago        13.3 kB
centos                                                   latest              5d0da3dc9764        3 months ago        231 MB
192.168.126.143:5000/google_containers/pause-amd64.3.0   latest              f9d5de079539        7 years ago         240 kB
192.168.156.130:5000/google_containers/pause-amd64.3.0   latest              f9d5de079539        7 years ago         240 kB
192.168.156.13:5000/google_containers/pause-amd64.3.0    latest              f9d5de079539        7 years ago         240 kB
docker.io/kubernetes/pause                               latest              f9d5de079539        7 years ago         240 kB
[root@localhost ~]# docker load -i test_centos.tar 
b7f31d0d1b04: Loading layer [==================================================>]  5.12 kB/5.12 kB
Loaded image: test_centos:1.0
[root@localhost ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
test_centos                                              1.0                 3702cc1d8602        2 minutes ago       231 MB
hello-world                                              latest              feb5d9fea6a5        2 months ago        13.3 kB
centos                                                   latest              5d0da3dc9764        3 months ago        231 MB
[root@localhost ~]# 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

?abc!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值