跨境派

跨境派

跨境派,专注跨境行业新闻资讯、跨境电商知识分享!

当前位置:首页 > 国内电商 > 4-Docker命令之docker commit

4-Docker命令之docker commit

时间:2024-04-26 16:40:19 来源:网络cs 作者:淼淼 栏目:国内电商 阅读:

标签: 命令 
阅读本书更多章节>>>>

1.docker commit介绍

docker commit命令是用于根据docker容器的改变创建一个新的docker镜像

2.docker commit用法

docker commit [参数] container [repository[:tag]]

[root@centos79 ~]# docker commit --helpUsage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]Create a new image from a container's changesAliases:  docker container commit, docker commitOptions:  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")  -c, --change list      Apply Dockerfile instruction to the created image  -m, --message string   Commit message  -p, --pause            Pause container during commit (default true)[root@centos79 ~]# 

3.实例

3.1.基于容器更改创建新镜像

-->进入运行中的docker容器

命令:

docker exec -it centos-ssh /bin/bash

[root@centos79 ~]# docker ps -a | grep centos-ssh803b6b35366a   centos-ssh:1.0         "/bin/sh -c '/usr/sb…"   12 minutes ago   Up 12 minutes   0.0.0.0:32768->22/tcp, :::32768->22/tcp                                                centos-ssh[root@centos79 ~]# docker exec -it centos-ssh /bin/bash[root@803b6b35366a ansible]# 

-->在容器内部使用vim命令

命令:

vim

[root@803b6b35366a ansible]# vimbash: vim: command not found[root@803b6b35366a ansible]# 

提示没有vim命令

-->docker容器内安装vim命令

命令:

yum install vim -y

[root@803b6b35366a ansible]# yum install vim -yLoaded plugins: fastestmirror, ovlhttp://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.base                                                                                                            | 3.6 kB  00:00:00     extras                                                                                                          | 2.9 kB  00:00:00     updates                                                                                                         | 2.9 kB  00:00:00     Loading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be installed--> Processing Dependency: vim-common = 2:7.4.629-8.el7_9 for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64--> Processing Dependency: which for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64--> Running transaction check---> Package gpm-libs.x86_64 0:1.20.7-6.el7 will be installed---> Package vim-common.x86_64 2:7.4.629-8.el7_9 will be installed--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-8.el7_9.x86_64---> Package which.x86_64 0:2.20-7.el7 will be installed--> Running transaction check---> Package vim-filesystem.x86_64 2:7.4.629-8.el7_9 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================= Package                            Arch                       Version                               Repository                   Size=======================================================================================================================================Installing: vim-enhanced                       x86_64                     2:7.4.629-8.el7_9                     updates                     1.1 MInstalling for dependencies: gpm-libs                           x86_64                     1.20.7-6.el7                          base                         32 k vim-common                         x86_64                     2:7.4.629-8.el7_9                     updates                     5.9 M vim-filesystem                     x86_64                     2:7.4.629-8.el7_9                     updates                      11 k which                              x86_64                     2.20-7.el7                            base                         41 kTransaction Summary=======================================================================================================================================Install  1 Package (+4 Dependent packages)Total download size: 7.1 MInstalled size: 23 MDownloading packages:(1/5): gpm-libs-1.20.7-6.el7.x86_64.rpm                                                                         |  32 kB  00:00:08     (2/5): vim-enhanced-7.4.629-8.el7_9.x86_64.rpm                                                                  | 1.1 MB  00:00:21     (3/5): vim-filesystem-7.4.629-8.el7_9.x86_64.rpm                                                                |  11 kB  00:00:03     (4/5): which-2.20-7.el7.x86_64.rpm                                                                              |  41 kB  00:00:06     vim-common-7.4.629-8.el7_9.x86 FAILED                                                                ]   99 B/s | 3.2 MB  11:12:56 ETA http://mirrors.163.com/centos/7/updates/x86_64/Packages/vim-common-7.4.629-8.el7_9.x86_64.rpm: [Errno 12] Timeout on http://mirrors.163.com/centos/7/updates/x86_64/Packages/vim-common-7.4.629-8.el7_9.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.vim-common-7.4.629-8.el7_9.x86 FAILED                                          http://mirrors.163.com/centos/7/updates/x86_64/Packages/vim-common-7.4.629-8.el7_9.x86_64.rpm: [Errno 12] Timeout on http://mirrors.163.com/centos/7/updates/x86_64/Packages/vim-common-7.4.629-8.el7_9.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.(5/5): vim-common-7.4.629-8.el7_9.x86_64.rpm                                                                    | 5.9 MB  00:02:02     ---------------------------------------------------------------------------------------------------------------------------------------Total                                                                                                   33 kB/s | 7.1 MB  00:03:35     Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                                                                             1/5   Installing : 2:vim-common-7.4.629-8.el7_9.x86_64                                                                                 2/5   Installing : which-2.20-7.el7.x86_64                                                                                             3/5 install-info: No such file or directory for /usr/share/info/which.info.gz  Installing : gpm-libs-1.20.7-6.el7.x86_64                                                                                        4/5   Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                                                                               5/5   Verifying  : gpm-libs-1.20.7-6.el7.x86_64                                                                                        1/5   Verifying  : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                                                                               2/5   Verifying  : which-2.20-7.el7.x86_64                                                                                             3/5   Verifying  : 2:vim-common-7.4.629-8.el7_9.x86_64                                                                                 4/5   Verifying  : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                                                                             5/5 Installed:  vim-enhanced.x86_64 2:7.4.629-8.el7_9                                                                                                Dependency Installed:  gpm-libs.x86_64 0:1.20.7-6.el7 vim-common.x86_64 2:7.4.629-8.el7_9 vim-filesystem.x86_64 2:7.4.629-8.el7_9 which.x86_64 0:2.20-7.el7Complete![root@803b6b35366a ansible]# which vim/bin/vim[root@803b6b35366a ansible]# 

-->退出docker容器,使用docker commit命令将此已经安装vim命令的docker容器进行commit,以便未来使用

命令:

exit

docker commit centos-ssh centos-vim:1.0

docker images | grep -i centos-vim

[root@803b6b35366a ansible]# exitexit[root@centos79 ~]# docker commit centos-ssh centos-vim:1.0sha256:fc50e118f3914fc6e29c5727b42aaed8bd9589c18fda540bcaae30ee563a906a[root@centos79 ~]# docker images | grep centos-vimcentos-vim                   1.0           fc50e118f391   29 seconds ago   1.01GB[root@centos79 ~]# 

-->基于新的镜像进行验证

命令:

docker run -itd -P --privileged --name centos-vim centos-vim:1.0

docker exec -it db944 /bin/bash

[root@centos79 ~]# docker run -itd -P --privileged --name centos-vim centos-vim:1.0db944665b1a0596f208b1fa2442bbf9540e6d868a885fb05edc1100f4888aeef[root@centos79 ~]# docker exec -it db944 /bin/bash[root@db944665b1a0 ansible]# which vim/bin/vim[root@db944665b1a0 ansible]# 

阅读本书更多章节>>>>

本文链接:https://www.kjpai.cn/guonei/2024-04-26/162589.html,文章来源:网络cs,作者:淼淼,版权归作者所有,如需转载请注明来源和作者,否则将追究法律责任!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。

文章评论