当前位置: 代码网 > 服务器>服务器>云虚拟主机 > Docker从零开始学习之Commit提交命令

Docker从零开始学习之Commit提交命令

2024年06月13日 云虚拟主机 我要评论
前言了解commit命令之前我们先了解下涉及的相关知识为什么这里又说镜像,因为之前了解的只是个大概,现在涉及镜像的原理基本概念镜像是一种轻量级、可执行的独立软件包,它包含运行某个软件所需的所有内容,我

前言 

了解commit命令之前我们先了解下涉及的相关知识

为什么这里又说镜像,因为之前了解的只是个大概,现在涉及镜像的原理

基本概念

镜像

  • 是一种轻量级、可执行的独立软件包,它包含运行某个软件所需的所有内容,我们把应用程序和配置依赖打包好形成一个可交付的运行环境(包括代码、运行时需要的库、环境变量和配置文件等),这个打包好的运行环境就是image镜像文件。
  • 只有通过这个镜像文件才能生成docker容器实例(类似java中new出来一个对象)。

镜像分层

什么是镜像分层

  • “镜像是有分层的”
    • 如图所示:
  • 镜像的使用的文件技术是unionfs
    • unionfs(联合文件系统)
      • unionfs(联合文件系统):union文件系统(unionfs)是一种分层、轻量级并且高性能的文件系统,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem)。union 文件系统是 docker 镜像的基础。镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
      • 特性:一次同时加载多个文件系统,但从外面看起来,只能看到一个文件系统,联合加载会把各层文件系统叠加起来,这样最终的文件系统会包含所有底层的文件和目录
  • docker镜像加载原理:
    • docker的镜像实际上由一层一层的文件系统组成,这种层级的文件系统unionfs。
    • bootfs(boot file system)主要包含bootloader和kernel, bootloader主要是引导加载kernel, linux刚启动时会加载bootfs文件系统,在docker镜像的最底层是引导文件系统bootfs。这一层与我们典型的linux/unix系统是一样的,包含boot加载器和内核。当boot加载完成之后整个内核就都在内存中了,此时内存的使用权已由bootfs转交给内核,此时系统也会卸载bootfs。
    • rootfs (root file system) ,在bootfs之上。包含的就是典型 linux 系统中的 /dev, /proc, /bin, /etc 等标准目录和文件。rootfs就是各种不同的操作系统发行版,比如ubuntu,centos等等。

对于一个精简的os,rootfs可以很小,只需要包括最基本的命令、工具和程序库就可以了,因为底层直接用host的kernel,自己只需要提供 rootfs 就行了。由此可见对于不同的linux发行版, bootfs基本是一致的, rootfs会有差别, 因此不同的发行版可以公用bootfs。

为什么 docker 镜像要采用这种分层结构

  • 比如说有多个镜像都从相同的 base 镜像构建而来,那么 docker host 只需在磁盘上保存一份 base 镜像;
    同时内存中也只需加载一份 base 镜像,就可以为所有容器服务了。而且镜像的每一层都可以被共享。

本章要点

  • docker镜像层都是只读的,容器层是可写的。
  • 当容器启动时,一个新的可写层被加载到镜像的顶部。这一层通常被称作“容器层”,“容器层”之下的都叫“镜像层”。
  • 所有对容器的改动 - 无论添加、删除、还是修改文件都只会发生在容器层中。只有容器层是可写的,容器层下面的所有镜像层都是只读的。

commit 命令

  • docker commit 命令用于根据 docker容器 的更改创建一个新的 dokcer镜像。该命令后面的 container 可以是容器id,或者是容器名。

命令格式

docker commit -m="[提交的描述信息]" -a="[作者]" [容器id] [新的镜像名称]:[新的镜像标签]

docker commit 操作参数

参数描述
-a, --author string作者。
-c, --change list应用 dockerfile 指令来创建图像。
-m, --messagestring
-p, --pause提交期间暂停容器(默认为true)。

实例演示

1.下载一个新的ubuntu镜像

[root@docker ~]# docker search ubuntu
name                             description                                      stars     official   automated
ubuntu                           ubuntu is a debian-based linux operating sys…   16622     [ok]       
websphere-liberty                websphere liberty multi-architecture images …   297       [ok]       
open-liberty                     open liberty multi-architecture images based…   62        [ok]       
neurodebian                      neurodebian provides neuroscience research s…   105       [ok]       
ubuntu-debootstrap               deprecated; use "ubuntu" instead                 52        [ok]       
ubuntu-upstart                   deprecated, as is upstart (find other proces…   115       [ok]       
ubuntu/nginx                     nginx, a high-performance reverse proxy & we…   102                  
ubuntu/squid                     squid is a caching proxy for the web. long-t…   70                   
ubuntu/cortex                    cortex provides storage for prometheus. long…   4                    
ubuntu/apache2                   apache, a secure & extensible open-source ht…   65                   
ubuntu/prometheus                prometheus is a systems and service monitori…   51                   
ubuntu/kafka                     apache kafka, a distributed event streaming …   37                   
ubuntu/bind9                     bind 9 is a very flexible, full-featured dns…   64                   
ubuntu/mysql                     mysql open source fast, stable, multi-thread…   54                   
ubuntu/zookeeper                 zookeeper maintains configuration informatio…   12                   
ubuntu/postgres                  postgresql is an open source object-relation…   31                   
ubuntu/redis                     redis, an open source key-value store. long-…   21                   
ubuntu/jre                       distroless java runtime based on ubuntu. lon…   9                    
ubuntu/grafana                   grafana, a feature rich metrics dashboard & …   9                    
ubuntu/dotnet-aspnet             chiselled ubuntu runtime image for asp.net a…   13                   
ubuntu/memcached                 memcached, in-memory keyvalue store for smal…   5                    
ubuntu/dotnet-deps               chiselled ubuntu for self-contained .net & a…   11                   
ubuntu/prometheus-alertmanager   alertmanager handles client alerts from prom…   9                    
ubuntu/dotnet-runtime            chiselled ubuntu runtime image for .net apps…   13                   
ubuntu/cassandra                 cassandra, an open source nosql distributed …   2                    
[root@docker ~]# docker pull ubuntu
using default tag: latest
latest: pulling from library/ubuntu
7b1a6ab2e44d: pull complete 
digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
status: downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[root@docker ~]# 

2.运行容器

[root@docker ~]# docker run -it ba6acccedd29 /bin/bash
root@792de8cbe835:/# 

3.查看并安装vim

[root@docker ~]# docker run -it ba6acccedd29 /bin/bash
root@ce128f008eea:/# vim aaa.txt 
oot@ce128f008eea:/# apt-get update
get:1 http://security.ubuntu.com/ubuntu focal-security inrelease [114 kb]
get:2 http://archive.ubuntu.com/ubuntu focal inrelease [265 kb]
get:3 http://security.ubuntu.com/ubuntu focal-security/main amd64 packages [3221 kb]
get:4 http://archive.ubuntu.com/ubuntu focal-updates inrelease [114 kb]
get:5 http://archive.ubuntu.com/ubuntu focal-backports inrelease [108 kb]
get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 packages [1275 kb]
get:7 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 packages [177 kb] 
get:8 http://archive.ubuntu.com/ubuntu focal/restricted amd64 packages [33.4 kb]
get:9 http://security.ubuntu.com/ubuntu focal-security/universe amd64 packages [1129 kb]
get:10 http://archive.ubuntu.com/ubuntu focal/universe amd64 packages [11.3 mb]            
get:11 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 packages [29.3 kb]
get:12 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 packages [3057 kb] 
get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 packages [1433 kb]      
get:14 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 packages [3206 kb]
get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 packages [3709 kb]                                                                                                                                                                                                                                                        
get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 packages [32.0 kb]                                                                                                                                                                                                                                                  
get:17 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 packages [55.2 kb]                                                                                                                                                                                                                                                      
get:18 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 packages [28.6 kb]                                                                                                                                                                                                                                                  
fetched 29.3 mb in 7s (4367 kb/s)                                                                                                                                                                                                                                                                                                          
reading package lists... done
root@ce128f008eea:/# apt-get install -y vim
reading package lists... done
building dependency tree       
reading state information... done
the following additional packages will be installed:
  alsa-topology-conf alsa-ucm-conf file libasound2 libasound2-data libcanberra0 libexpat1 libgpm2 libltdl7 libmagic-mgc libmagic1 libmpdec2 libogg0 libpython3.8 libpython3.8-minimal libpython3.8-stdlib libreadline8 libsqlite3-0 libssl1.1 libtdb1 libvorbis0a libvorbisfile3 mime-support readline-common sound-theme-freedesktop
  vim-common vim-runtime xxd xz-utils
suggested packages:
  libasound2-plugins alsa-utils libcanberra-gtk0 libcanberra-pulse gpm readline-doc ctags vim-doc vim-scripts
the following new packages will be installed:
  alsa-topology-conf alsa-ucm-conf file libasound2 libasound2-data libcanberra0 libexpat1 libgpm2 libltdl7 libmagic-mgc libmagic1 libmpdec2 libogg0 libpython3.8 libpython3.8-minimal libpython3.8-stdlib libreadline8 libsqlite3-0 libssl1.1 libtdb1 libvorbis0a libvorbisfile3 mime-support readline-common sound-theme-freedesktop vim
  vim-common vim-runtime xxd xz-utils
0 upgraded, 30 newly installed, 0 to remove and 51 not upgraded.
need to get 15.0 mb of archives.
after this operation, 70.6 mb of additional disk space will be used.
get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libmagic-mgc amd64 1:5.38-4 [218 kb]
get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libmagic1 amd64 1:5.38-4 [75.9 kb]
get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 file amd64 1:5.38-4 [23.3 kb]
get:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libexpat1 amd64 2.2.9-1ubuntu0.6 [74.6 kb]
get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 libmpdec2 amd64 2.4.2-3 [81.1 kb]
get:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.20 [1321 kb]
get:7 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8-minimal amd64 3.8.10-0ubuntu1~20.04.8 [717 kb]
get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 mime-support all 3.64ubuntu1 [30.6 kb]
get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 readline-common all 8.0-4 [53.5 kb]
get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 libreadline8 amd64 8.0-4 [131 kb]
get:11 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libsqlite3-0 amd64 3.31.1-4ubuntu0.5 [549 kb]
get:12 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8-stdlib amd64 3.8.10-0ubuntu1~20.04.8 [1675 kb]
get:13 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 xxd amd64 2:8.1.2269-1ubuntu5.20 [52.6 kb]
get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 vim-common all 2:8.1.2269-1ubuntu5.20 [87.6 kb]
get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 xz-utils amd64 5.2.4-1ubuntu1.1 [82.6 kb]
get:16 http://archive.ubuntu.com/ubuntu focal/main amd64 alsa-topology-conf all 1.2.2-1 [7364 b]
get:17 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 alsa-ucm-conf all 1.2.2-1ubuntu0.13 [27.0 kb]
get:18 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libasound2-data all 1.2.2-2.1ubuntu2.5 [20.1 kb]
get:19 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libasound2 amd64 1.2.2-2.1ubuntu2.5 [335 kb]
get:20 http://archive.ubuntu.com/ubuntu focal/main amd64 libltdl7 amd64 2.4.6-14 [38.5 kb]
get:21 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libtdb1 amd64 1.4.5-0ubuntu0.20.04.1 [44.2 kb]
get:22 http://archive.ubuntu.com/ubuntu focal/main amd64 libogg0 amd64 1.3.4-0ubuntu1 [24.0 kb]
get:23 http://archive.ubuntu.com/ubuntu focal/main amd64 libvorbis0a amd64 1.3.6-2ubuntu1 [87.0 kb]
get:24 http://archive.ubuntu.com/ubuntu focal/main amd64 libvorbisfile3 amd64 1.3.6-2ubuntu1 [16.1 kb]
get:25 http://archive.ubuntu.com/ubuntu focal/main amd64 sound-theme-freedesktop all 0.8-2ubuntu1 [384 kb]
get:26 http://archive.ubuntu.com/ubuntu focal/main amd64 libcanberra0 amd64 0.30-7ubuntu1 [38.1 kb]
get:27 http://archive.ubuntu.com/ubuntu focal/main amd64 libgpm2 amd64 1.20.7-5 [15.1 kb]
get:28 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8 amd64 3.8.10-0ubuntu1~20.04.8 [1625 kb]
get:29 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 vim-runtime all 2:8.1.2269-1ubuntu5.20 [5878 kb]
get:30 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 vim amd64 2:8.1.2269-1ubuntu5.20 [1242 kb]
fetched 15.0 mb in 5s (2983 kb/s)
debconf: delaying package configuration, since apt-utils is not installed
selecting previously unselected package libmagic-mgc.
(reading database ... 4127 files and directories currently installed.)
preparing to unpack .../00-libmagic-mgc_1%3a5.38-4_amd64.deb ...
unpacking libmagic-mgc (1:5.38-4) ...
selecting previously unselected package libmagic1:amd64.
preparing to unpack .../01-libmagic1_1%3a5.38-4_amd64.deb ...
unpacking libmagic1:amd64 (1:5.38-4) ...
selecting previously unselected package file.
preparing to unpack .../02-file_1%3a5.38-4_amd64.deb ...
unpacking file (1:5.38-4) ...
selecting previously unselected package libexpat1:amd64.
preparing to unpack .../03-libexpat1_2.2.9-1ubuntu0.6_amd64.deb ...
unpacking libexpat1:amd64 (2.2.9-1ubuntu0.6) ...
selecting previously unselected package libmpdec2:amd64.
preparing to unpack .../04-libmpdec2_2.4.2-3_amd64.deb ...
unpacking libmpdec2:amd64 (2.4.2-3) ...
selecting previously unselected package libssl1.1:amd64.
preparing to unpack .../05-libssl1.1_1.1.1f-1ubuntu2.20_amd64.deb ...
unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.20) ...
selecting previously unselected package libpython3.8-minimal:amd64.
preparing to unpack .../06-libpython3.8-minimal_3.8.10-0ubuntu1~20.04.8_amd64.deb ...
unpacking libpython3.8-minimal:amd64 (3.8.10-0ubuntu1~20.04.8) ...
selecting previously unselected package mime-support.
preparing to unpack .../07-mime-support_3.64ubuntu1_all.deb ...
unpacking mime-support (3.64ubuntu1) ...
selecting previously unselected package readline-common.
preparing to unpack .../08-readline-common_8.0-4_all.deb ...
unpacking readline-common (8.0-4) ...
selecting previously unselected package libreadline8:amd64.
preparing to unpack .../09-libreadline8_8.0-4_amd64.deb ...
unpacking libreadline8:amd64 (8.0-4) ...
selecting previously unselected package libsqlite3-0:amd64.
preparing to unpack .../10-libsqlite3-0_3.31.1-4ubuntu0.5_amd64.deb ...
unpacking libsqlite3-0:amd64 (3.31.1-4ubuntu0.5) ...
selecting previously unselected package libpython3.8-stdlib:amd64.
preparing to unpack .../11-libpython3.8-stdlib_3.8.10-0ubuntu1~20.04.8_amd64.deb ...
unpacking libpython3.8-stdlib:amd64 (3.8.10-0ubuntu1~20.04.8) ...
selecting previously unselected package xxd.
preparing to unpack .../12-xxd_2%3a8.1.2269-1ubuntu5.20_amd64.deb ...
unpacking xxd (2:8.1.2269-1ubuntu5.20) ...
selecting previously unselected package vim-common.
preparing to unpack .../13-vim-common_2%3a8.1.2269-1ubuntu5.20_all.deb ...
unpacking vim-common (2:8.1.2269-1ubuntu5.20) ...
selecting previously unselected package xz-utils.
preparing to unpack .../14-xz-utils_5.2.4-1ubuntu1.1_amd64.deb ...
unpacking xz-utils (5.2.4-1ubuntu1.1) ...
selecting previously unselected package alsa-topology-conf.
preparing to unpack .../15-alsa-topology-conf_1.2.2-1_all.deb ...
unpacking alsa-topology-conf (1.2.2-1) ...
selecting previously unselected package alsa-ucm-conf.
preparing to unpack .../16-alsa-ucm-conf_1.2.2-1ubuntu0.13_all.deb ...
unpacking alsa-ucm-conf (1.2.2-1ubuntu0.13) ...
selecting previously unselected package libasound2-data.
preparing to unpack .../17-libasound2-data_1.2.2-2.1ubuntu2.5_all.deb ...
unpacking libasound2-data (1.2.2-2.1ubuntu2.5) ...
selecting previously unselected package libasound2:amd64.
preparing to unpack .../18-libasound2_1.2.2-2.1ubuntu2.5_amd64.deb ...
unpacking libasound2:amd64 (1.2.2-2.1ubuntu2.5) ...
selecting previously unselected package libltdl7:amd64.
preparing to unpack .../19-libltdl7_2.4.6-14_amd64.deb ...
unpacking libltdl7:amd64 (2.4.6-14) ...
selecting previously unselected package libtdb1:amd64.
preparing to unpack .../20-libtdb1_1.4.5-0ubuntu0.20.04.1_amd64.deb ...
unpacking libtdb1:amd64 (1.4.5-0ubuntu0.20.04.1) ...
selecting previously unselected package libogg0:amd64.
preparing to unpack .../21-libogg0_1.3.4-0ubuntu1_amd64.deb ...
unpacking libogg0:amd64 (1.3.4-0ubuntu1) ...
selecting previously unselected package libvorbis0a:amd64.
preparing to unpack .../22-libvorbis0a_1.3.6-2ubuntu1_amd64.deb ...
unpacking libvorbis0a:amd64 (1.3.6-2ubuntu1) ...
selecting previously unselected package libvorbisfile3:amd64.
preparing to unpack .../23-libvorbisfile3_1.3.6-2ubuntu1_amd64.deb ...
unpacking libvorbisfile3:amd64 (1.3.6-2ubuntu1) ...
selecting previously unselected package sound-theme-freedesktop.
preparing to unpack .../24-sound-theme-freedesktop_0.8-2ubuntu1_all.deb ...
unpacking sound-theme-freedesktop (0.8-2ubuntu1) ...
selecting previously unselected package libcanberra0:amd64.
preparing to unpack .../25-libcanberra0_0.30-7ubuntu1_amd64.deb ...
unpacking libcanberra0:amd64 (0.30-7ubuntu1) ...
selecting previously unselected package libgpm2:amd64.
preparing to unpack .../26-libgpm2_1.20.7-5_amd64.deb ...
unpacking libgpm2:amd64 (1.20.7-5) ...
selecting previously unselected package libpython3.8:amd64.
preparing to unpack .../27-libpython3.8_3.8.10-0ubuntu1~20.04.8_amd64.deb ...
unpacking libpython3.8:amd64 (3.8.10-0ubuntu1~20.04.8) ...
selecting previously unselected package vim-runtime.
preparing to unpack .../28-vim-runtime_2%3a8.1.2269-1ubuntu5.20_all.deb ...
adding 'diversion of /usr/share/vim/vim81/doc/help.txt to /usr/share/vim/vim81/doc/help.txt.vim-tiny by vim-runtime'
adding 'diversion of /usr/share/vim/vim81/doc/tags to /usr/share/vim/vim81/doc/tags.vim-tiny by vim-runtime'
unpacking vim-runtime (2:8.1.2269-1ubuntu5.20) ...
selecting previously unselected package vim.
preparing to unpack .../29-vim_2%3a8.1.2269-1ubuntu5.20_amd64.deb ...
unpacking vim (2:8.1.2269-1ubuntu5.20) ...
setting up libexpat1:amd64 (2.2.9-1ubuntu0.6) ...
setting up libgpm2:amd64 (1.20.7-5) ...
setting up libogg0:amd64 (1.3.4-0ubuntu1) ...
setting up mime-support (3.64ubuntu1) ...
setting up alsa-ucm-conf (1.2.2-1ubuntu0.13) ...
setting up libmagic-mgc (1:5.38-4) ...
setting up libtdb1:amd64 (1.4.5-0ubuntu0.20.04.1) ...
setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.20) ...
debconf: unable to initialize frontend: dialog
debconf: (no usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/debconf/frontend/dialog.pm line 76.)
debconf: falling back to frontend: readline
debconf: unable to initialize frontend: readline
debconf: (can't locate term/readline.pm in @inc (you may need to install the term::readline module) (@inc contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/debconf/frontend/readline.pm line 7.)
debconf: falling back to frontend: teletype
setting up libsqlite3-0:amd64 (3.31.1-4ubuntu0.5) ...
setting up libmagic1:amd64 (1:5.38-4) ...
setting up file (1:5.38-4) ...
setting up xxd (2:8.1.2269-1ubuntu5.20) ...
setting up libasound2-data (1.2.2-2.1ubuntu2.5) ...
setting up vim-common (2:8.1.2269-1ubuntu5.20) ...
setting up xz-utils (5.2.4-1ubuntu1.1) ...
update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/lzma.1.gz because associated file /usr/share/man/man1/xz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/unlzma.1.gz because associated file /usr/share/man/man1/unxz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcat.1.gz because associated file /usr/share/man/man1/xzcat.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzmore.1.gz because associated file /usr/share/man/man1/xzmore.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzless.1.gz because associated file /usr/share/man/man1/xzless.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzdiff.1.gz because associated file /usr/share/man/man1/xzdiff.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcmp.1.gz because associated file /usr/share/man/man1/xzcmp.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzgrep.1.gz because associated file /usr/share/man/man1/xzgrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzegrep.1.gz because associated file /usr/share/man/man1/xzegrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzfgrep.1.gz because associated file /usr/share/man/man1/xzfgrep.1.gz (of link group lzma) doesn't exist
setting up libvorbis0a:amd64 (1.3.6-2ubuntu1) ...
setting up libltdl7:amd64 (2.4.6-14) ...
setting up alsa-topology-conf (1.2.2-1) ...
setting up sound-theme-freedesktop (0.8-2ubuntu1) ...
setting up libasound2:amd64 (1.2.2-2.1ubuntu2.5) ...
setting up libmpdec2:amd64 (2.4.2-3) ...
setting up vim-runtime (2:8.1.2269-1ubuntu5.20) ...
setting up readline-common (8.0-4) ...
setting up libpython3.8-minimal:amd64 (3.8.10-0ubuntu1~20.04.8) ...
setting up libreadline8:amd64 (8.0-4) ...
setting up libvorbisfile3:amd64 (1.3.6-2ubuntu1) ...
setting up libpython3.8-stdlib:amd64 (3.8.10-0ubuntu1~20.04.8) ...
setting up libcanberra0:amd64 (0.30-7ubuntu1) ...
setting up libpython3.8:amd64 (3.8.10-0ubuntu1~20.04.8) ...
setting up vim (2:8.1.2269-1ubuntu5.20) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/da/man1/vi.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/vi.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/vi.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/vi.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/vi.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/vi.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/vi.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/vi.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/da/man1/view.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/view.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/view.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/view.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/view.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/view.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/view.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/view.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/da/man1/ex.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/ex.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/ex.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/ex.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/ex.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/ex.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/ex.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/ex.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/da/man1/editor.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/editor.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/editor.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/editor.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/editor.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/editor.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/editor.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group editor) doesn't exist
processing triggers for libc-bin (2.31-0ubuntu9.2) ...
root@ce128f008eea:/# 

4.退出容器

root@ce128f008eea:/# exit
exit
[root@docker ~]# 

5提交自己的镜像

[root@docker ~]# docker ps -a
container id   image           command                   created              status                            ports     names
dd90b084d152   ubuntu:latest   "/bin/bash"               about a minute ago   up about a minute                           ubuntu_vim
ccb457c15659   mysql:5.6       "docker-entrypoint.s…"   49 minutes ago       exited (1) 49 minutes ago                   relaxed_bartik
f919fcfcb7b0   hello-world     "/hello"                  19 hours ago         exited (0) 19 hours ago                     fervent_benz
a4016a83fc04   hello-world     "/hello"                  23 hours ago         exited (0) 23 hours ago                     hopeful_bardeen
f30bd054e899   9c7a54a9a43c    "/hello"                  40 hours ago         exited (0) 40 hours ago                     mystifying_shockley
[root@docker ~]# docker commit -m="installed vim" -a="circle" dd90b084d152 cirlce/ubuntu:1.0
sha256:4eac314fbf24dffd018c0682a47044f4108f5fef02d8af5d6a79e91c8bfa0765
[root@docker ~]#

对比

[root@docker ~]# docker images
repository      tag       image id       created         size
'cirlce/ubuntu'   1.0       4eac314fbf24   2 minutes ago   72.8mb
mysql           5.6       dd3b2a5dcb48   23 months ago   303mb
'ubuntu'          latest    ba6acccedd29   2 years ago     72.8mb
hello-world     latest    feb5d9fea6a5   2 years ago     13.3kb
[root@docker ~]# 

总结

  • docker中的镜像分层,支持通过扩展现有镜像,创建新的镜像。类似java继承于一个base基础类,自己再按需扩展。
  • 新镜像是从 base 镜像一层一层叠加生成的。每安装一个软件,就在现有镜像的基础上增加一层

到此这篇关于docker从零开始学习之commit提交命令的文章就介绍到这了,更多相关docker commit提交命令内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

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

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com