当前位置: 首页 > news >正文

4-Docker命令之docker commit

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-ssh
803b6b35366a   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]# vim
bash: vim: command not found
[root@803b6b35366a ansible]# 

提示没有vim命令

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

命令:

yum install vim -y

[root@803b6b35366a ansible]# yum install vim -y
Loaded plugins: fastestmirror, ovl
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.
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 hostfile
Resolving 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 M
Installing for dependencies:gpm-libs                           x86_64                     1.20.7-6.el7                          base                         32 kvim-common                         x86_64                     2:7.4.629-8.el7_9                     updates                     5.9 Mvim-filesystem                     x86_64                     2:7.4.629-8.el7_9                     updates                      11 kwhich                              x86_64                     2.20-7.el7                            base                         41 kTransaction Summary
=======================================================================================================================================
Install  1 Package (+4 Dependent packages)Total download size: 7.1 M
Installed size: 23 M
Downloading 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 check
Running transaction test
Transaction test succeeded
Running transactionInstalling : 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.gzInstalling : 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]# exit
exit
[root@centos79 ~]# docker commit centos-ssh centos-vim:1.0
sha256:fc50e118f3914fc6e29c5727b42aaed8bd9589c18fda540bcaae30ee563a906a
[root@centos79 ~]# docker images | grep centos-vim
centos-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.0
db944665b1a0596f208b1fa2442bbf9540e6d868a885fb05edc1100f4888aeef
[root@centos79 ~]# docker exec -it db944 /bin/bash
[root@db944665b1a0 ansible]# which vim
/bin/vim
[root@db944665b1a0 ansible]# 

http://www.lryc.cn/news/257258.html

相关文章:

  • RabbitMQ学习笔记10 综合实战 实现新商家规定时间内上架商品检查
  • Project Euler 865 Triplicate Numbers(线性dp)
  • 计算机网络测试题第二部分
  • linux 15day apache apache服务安装 httpd服务器 安装虚拟主机系统 一个主机 多个域名如何绑定
  • Linux和Windows环境下如何使用gitee?
  • Docker安装教程
  • 【PWN】学习笔记(二)【栈溢出基础】
  • 02-Nacos和Eureka的区别与联系
  • 常见的Linux系统版本
  • 基于JavaWeb+SSM+Vue微信小程序的科创微应用平台系统的设计和实现
  • 【Spring Boot 源码学习】ApplicationListener 详解
  • HCIP---RSTP/MSTP
  • 探索开源游戏的乐趣与无限可能 | 开源专题 No.47
  • springboot_3.2_freemark_基础环境配置
  • 【MySQL】MySQL 在 Centos 7环境安装教程
  • 有病但合理的 ChatGPT 提示语
  • this.$emit(‘update:isVisible‘, false)作用
  • CnetSDK .NET OCR Library SDK Crack
  • 基于Solr的全文检索系统的实现与应用
  • 【rabbitMQ】rabbitMQ控制台模拟收发消息
  • Java NIO, IO 整理
  • 【数据结构】——排序篇(下)
  • C++ 模拟实现vector
  • 基于hadoop下的spark安装
  • 面试经典150题(10-13)
  • Sql server数据库数据查询
  • 前端开发tips
  • 实现跨VLAN通信、以及RIP路由协议的配置
  • 使用python绘制现有彩票记录走势图
  • Kubernetes实战(十)-升级k8s集群