跳到主要内容

2、Commit

实战:利用commit命令来构建镜像(不推荐)-2022.2.28

1、用法

docker commit 容器id 镜像name:tag

2、举例

step1:运行一个centos容器
[root@xyy admin]###docker run -it -d centos
608078af64734e4a199b75ce337959e22c2944464a4a9f723fcc3ad2e8d42d85
[root@xyy admin]###docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
608078af6473 centos "/bin/bash" 3 seconds ago Up 2 seconds boring_meninsky

step2:进到这个centos容器里面,构建好我们需要的环境
[root@xyy admin]###docker exec -it 608078af6473 bash
[root@608078af6473 /]### yum install nginx
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream 2.3 MB/s | 8.1 MB 00:03
CentOS Linux 8 - BaseOS 5.8 MB/s | 3.5 MB 00:00
^CCentOS Linux 8 - Extras 1.9 kB/s | 6.6 kB 00:03
Error: Failed to download metadata for repo 'extras': Librepo was interrupted by a signal
[root@608078af6473 /]### exit
exit

step3:使用commit命令将容器转换成我们需要的镜像
###先来查看下当前本地镜像信息
[root@xyy admin]###docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 2 months ago 231MB

###开始构建镜像
[root@xyy admin]###docker commit 608078af6473 test-commit-command:v1
sha256:8fa14905fbf663736f24188e2d2a1a1ca08621c2672b7e64ac7c58adf46b66ac

step4:构建完成后我们验证下
[root@xyy admin]###docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test-commit-command v1 8fa14905fbf6 9 seconds ago 257MB
centos latest 5d0da3dc9764 2 months ago 231MB
[root@xyy admin]###docker commit

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码 x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号 《云原生架构师实战》

image-20230107215126971

🍀 个人博客站点

http://47.97.48.237/ (即将上线域名:onedayxyy.cn)

image-20230917111843405

🍀 语雀

https://www.yuque.com/xyy-onlyone

image-20230912072007284

🍀 csdn https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

image-20230107215149885

🍀 知乎 https://www.zhihu.com/people/foryouone

image-20230107215203185

最后

好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!