110_DockerFile


DockerFile简介

image.png

查看centos是如何做的

:::info
docker仓库:https://hub.docker.com/
:::
image.png
image.png
image.png

DockerFile基础知识

image.png
image.png
image.png

DockerFile的指令

image.png
image.png

实战测试:创建自己的centos

参考

image.png
image.png
image.png
image.png
image.png
image.png
image.png

实战

编写dockerfile文件

[root@ecs-214025 admin]# cd /home/
[root@ecs-214025 home]# ls
admin  ceshi  docker-test-volume  eqroot  mysql  ruoyi
[root@ecs-214025 home]# mkdir dockerfile
[root@ecs-214025 home]# cd dockerfile/
[root@ecs-214025 dockerfile]# ls
[root@ecs-214025 dockerfile]# vim mydockerfile-centos

FROM centos
MAINTAINER zhyq<wl3pbzhyq@163.com>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo "---end---"
CMD /bin/bash

[root@ecs-214025 dockerfile]# cat mydockerfile-centos 
FROM centos
MAINTAINER zhyq<wl3pbzhyq@163.com>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo "---end---"
CMD /bin/bash
[root@ecs-214025 dockerfile]# 

生成镜像

:::info
docker build -f mydockerfile-centos -t mycentos:0.1 .
注意:末尾的“.”必须写
:::
:::info
生成镜像报错:Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
报错原因:Centos8于2021年年底停止了服务,大家再在使用yum源安装时候,会出现错误
参考文档:https://blog.csdn.net/qq_43762191/article/details/124474377
:::

[root@ecs-214025 dockerfile]# docker build -f mydockerfile-centos -t mycentos:0.1 .
Sending build context to Docker daemon  2.048kB
Step 1/10 : FROM centos
 ---> 5d0da3dc9764
Step 2/10 : MAINTAINER zhyq<wl3pbzhyq@163.com>
 ---> Running in d5adfe8510e1
Removing intermediate container d5adfe8510e1
 ---> c8b979a47824
Step 3/10 : ENV MYPATH /usr/local
 ---> Running in 95efee165e86
Removing intermediate container 95efee165e86
 ---> 78f0232e4ab9
Step 4/10 : WORKDIR $MYPATH
 ---> Running in 2923ea7111bd
Removing intermediate container 2923ea7111bd
 ---> 64c28bbdf9b3
Step 5/10 : RUN yum -y install vim
 ---> Running in e1e03945f75d
CentOS Linux 8 - AppStream                       47  B/s |  38  B     00:00    
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum -y install vim' returned a non-zero code: 1
[root@ecs-214025 dockerfile]# 

:::info
解决方法:使用centos:7作为基础镜像
FROM centos:7
:::

[root@ecs-214025 dockerfile]# vim mydockerfile-centos

FROM centos:7
MAINTAINER zhyq<wl3pbzhyq@163.com>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo "---end---"
CMD /bin/bash

[root@ecs-214025 dockerfile]# docker build -f mydockerfile-centos -t mycentos:0.1 .
Sending build context to Docker daemon  2.048kB
Step 1/10 : FROM centos:7
 ---> eeb6ee3f44bd
Step 2/10 : MAINTAINER zhyq<wl3pbzhyq@163.com>
 ---> Running in 8240d25e94e8
Removing intermediate container 8240d25e94e8
 ---> 71997e6af231
Step 3/10 : ENV MYPATH /usr/local
 ---> Running in 6c1a75869072
Removing intermediate container 6c1a75869072
 ---> b8a05fb667b6
Step 4/10 : WORKDIR $MYPATH
 ---> Running in 0f00c3843d11
Removing intermediate container 0f00c3843d11
 ---> b79aa9b42c1b
Step 5/10 : RUN yum -y install vim
 ---> Running in ba98100f1fd0
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
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: perl(:MODULE_COMPAT_5.16.3) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: libperl.so()(64bit) 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 perl.x86_64 4:5.16.3-299.el7_9 will be installed
--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-299.el7_9.x86_64
---> Package perl-libs.x86_64 4:5.16.3-299.el7_9 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 perl-Carp.noarch 0:1.26-244.el7 will be installed
---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch
---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
--> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
---> Package perl-Socket.x86_64 0:2.010-5.el7 will be installed
---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
---> Package perl-constant.noarch 0:1.27-2.el7 will be installed
---> Package perl-macros.x86_64 4:5.16.3-299.el7_9 will be installed
---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
---> Package vim-filesystem.x86_64 2:7.4.629-8.el7_9 will be installed
--> Running transaction check
---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
---> Package perl-Pod-Escapes.noarch 1:1.04-299.el7_9 will be installed
---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
--> Running transaction check
---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
---> Package perl-parent.noarch 1:0.225-244.el7 will be installed
--> Finished Dependency Resolution

Dependencies 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 k
 groff-base                 x86_64     1.22.2-8.el7           base        942 k
 perl                       x86_64     4:5.16.3-299.el7_9     updates     8.0 M
 perl-Carp                  noarch     1.26-244.el7           base         19 k
 perl-Encode                x86_64     2.51-7.el7             base        1.5 M
 perl-Exporter              noarch     5.68-3.el7             base         28 k
 perl-File-Path             noarch     2.09-2.el7             base         26 k
 perl-File-Temp             noarch     0.23.01-3.el7          base         56 k
 perl-Filter                x86_64     1.49-3.el7             base         76 k
 perl-Getopt-Long           noarch     2.40-3.el7             base         56 k
 perl-HTTP-Tiny             noarch     0.033-3.el7            base         38 k
 perl-PathTools             x86_64     3.40-5.el7             base         82 k
 perl-Pod-Escapes           noarch     1:1.04-299.el7_9       updates      52 k
 perl-Pod-Perldoc           noarch     3.20-4.el7             base         87 k
 perl-Pod-Simple            noarch     1:3.28-4.el7           base        216 k
 perl-Pod-Usage             noarch     1.63-3.el7             base         27 k
 perl-Scalar-List-Utils     x86_64     1.27-248.el7           base         36 k
 perl-Socket                x86_64     2.010-5.el7            base         49 k
 perl-Storable              x86_64     2.45-3.el7             base         77 k
 perl-Text-ParseWords       noarch     3.29-4.el7             base         14 k
 perl-Time-HiRes            x86_64     4:1.9725-3.el7         base         45 k
 perl-Time-Local            noarch     1.2300-2.el7           base         24 k
 perl-constant              noarch     1.27-2.el7             base         19 k
 perl-libs                  x86_64     4:5.16.3-299.el7_9     updates     690 k
 perl-macros                x86_64     4:5.16.3-299.el7_9     updates      44 k
 perl-parent                noarch     1:0.225-244.el7        base         12 k
 perl-podlators             noarch     2.5.1-3.el7            base        112 k
 perl-threads               x86_64     1.87-4.el7             base         49 k
 perl-threads-shared        x86_64     1.43-6.el7             base         39 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 k

Transaction Summary
================================================================================
Install  1 Package (+32 Dependent packages)

Total download size: 19 M
Installed size: 63 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/gpm-libs-1.20.7-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for gpm-libs-1.20.7-6.el7.x86_64.rpm is not installed
Public key for perl-5.16.3-299.el7_9.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total                                               12 MB/s |  19 MB  00:01     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-9.2009.0.el7.centos.x86_64 (@CentOS)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gpm-libs-1.20.7-6.el7.x86_64                                1/33 
  Installing : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                     2/33 
  Installing : 2:vim-common-7.4.629-8.el7_9.x86_64                         3/33 
  Installing : which-2.20-7.el7.x86_64                                     4/33 
install-info: No such file or directory for /usr/share/info/which.info.gz
  Installing : groff-base-1.22.2-8.el7.x86_64                              5/33 
  Installing : 1:perl-parent-0.225-244.el7.noarch                          6/33 
  Installing : perl-HTTP-Tiny-0.033-3.el7.noarch                           7/33 
  Installing : perl-podlators-2.5.1-3.el7.noarch                           8/33 
  Installing : perl-Pod-Perldoc-3.20-4.el7.noarch                          9/33 
  Installing : 1:perl-Pod-Escapes-1.04-299.el7_9.noarch                   10/33 
  Installing : perl-Encode-2.51-7.el7.x86_64                              11/33 
  Installing : perl-Text-ParseWords-3.29-4.el7.noarch                     12/33 
  Installing : perl-Pod-Usage-1.63-3.el7.noarch                           13/33 
  Installing : 4:perl-macros-5.16.3-299.el7_9.x86_64                      14/33 
  Installing : perl-Storable-2.45-3.el7.x86_64                            15/33 
  Installing : perl-Exporter-5.68-3.el7.noarch                            16/33 
  Installing : perl-constant-1.27-2.el7.noarch                            17/33 
  Installing : perl-Socket-2.010-5.el7.x86_64                             18/33 
  Installing : perl-Time-Local-1.2300-2.el7.noarch                        19/33 
  Installing : perl-Carp-1.26-244.el7.noarch                              20/33 
  Installing : perl-PathTools-3.40-5.el7.x86_64                           21/33 
  Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64                 22/33 
  Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch                        23/33 
  Installing : perl-File-Temp-0.23.01-3.el7.noarch                        24/33 
  Installing : perl-File-Path-2.09-2.el7.noarch                           25/33 
  Installing : perl-threads-shared-1.43-6.el7.x86_64                      26/33 
  Installing : perl-threads-1.87-4.el7.x86_64                             27/33 
  Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                      28/33 
  Installing : perl-Filter-1.49-3.el7.x86_64                              29/33 
  Installing : 4:perl-libs-5.16.3-299.el7_9.x86_64                        30/33 
  Installing : perl-Getopt-Long-2.40-3.el7.noarch                         31/33 
  Installing : 4:perl-5.16.3-299.el7_9.x86_64                             32/33 
  Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                      33/33 
  Verifying  : perl-HTTP-Tiny-0.033-3.el7.noarch                           1/33 
  Verifying  : perl-threads-shared-1.43-6.el7.x86_64                       2/33 
  Verifying  : perl-Storable-2.45-3.el7.x86_64                             3/33 
  Verifying  : groff-base-1.22.2-8.el7.x86_64                              4/33 
  Verifying  : perl-Exporter-5.68-3.el7.noarch                             5/33 
  Verifying  : perl-constant-1.27-2.el7.noarch                             6/33 
  Verifying  : perl-PathTools-3.40-5.el7.x86_64                            7/33 
  Verifying  : 4:perl-macros-5.16.3-299.el7_9.x86_64                       8/33 
  Verifying  : 2:vim-enhanced-7.4.629-8.el7_9.x86_64                       9/33 
  Verifying  : 1:perl-parent-0.225-244.el7.noarch                         10/33 
  Verifying  : perl-Socket-2.010-5.el7.x86_64                             11/33 
  Verifying  : which-2.20-7.el7.x86_64                                    12/33 
  Verifying  : 2:vim-filesystem-7.4.629-8.el7_9.x86_64                    13/33 
  Verifying  : perl-File-Temp-0.23.01-3.el7.noarch                        14/33 
  Verifying  : 1:perl-Pod-Simple-3.28-4.el7.noarch                        15/33 
  Verifying  : perl-Time-Local-1.2300-2.el7.noarch                        16/33 
  Verifying  : 1:perl-Pod-Escapes-1.04-299.el7_9.noarch                   17/33 
  Verifying  : perl-Carp-1.26-244.el7.noarch                              18/33 
  Verifying  : 2:vim-common-7.4.629-8.el7_9.x86_64                        19/33 
  Verifying  : perl-Scalar-List-Utils-1.27-248.el7.x86_64                 20/33 
  Verifying  : perl-Pod-Usage-1.63-3.el7.noarch                           21/33 
  Verifying  : perl-Encode-2.51-7.el7.x86_64                              22/33 
  Verifying  : perl-Pod-Perldoc-3.20-4.el7.noarch                         23/33 
  Verifying  : perl-podlators-2.5.1-3.el7.noarch                          24/33 
  Verifying  : 4:perl-5.16.3-299.el7_9.x86_64                             25/33 
  Verifying  : perl-File-Path-2.09-2.el7.noarch                           26/33 
  Verifying  : perl-threads-1.87-4.el7.x86_64                             27/33 
  Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                      28/33 
  Verifying  : gpm-libs-1.20.7-6.el7.x86_64                               29/33 
  Verifying  : perl-Filter-1.49-3.el7.x86_64                              30/33 
  Verifying  : perl-Getopt-Long-2.40-3.el7.noarch                         31/33 
  Verifying  : perl-Text-ParseWords-3.29-4.el7.noarch                     32/33 
  Verifying  : 4:perl-libs-5.16.3-299.el7_9.x86_64                        33/33 

Installed:
  vim-enhanced.x86_64 2:7.4.629-8.el7_9                                         

Dependency Installed:
  gpm-libs.x86_64 0:1.20.7-6.el7                                                
  groff-base.x86_64 0:1.22.2-8.el7                                              
  perl.x86_64 4:5.16.3-299.el7_9                                                
  perl-Carp.noarch 0:1.26-244.el7                                               
  perl-Encode.x86_64 0:2.51-7.el7                                               
  perl-Exporter.noarch 0:5.68-3.el7                                             
  perl-File-Path.noarch 0:2.09-2.el7                                            
  perl-File-Temp.noarch 0:0.23.01-3.el7                                         
  perl-Filter.x86_64 0:1.49-3.el7                                               
  perl-Getopt-Long.noarch 0:2.40-3.el7                                          
  perl-HTTP-Tiny.noarch 0:0.033-3.el7                                           
  perl-PathTools.x86_64 0:3.40-5.el7                                            
  perl-Pod-Escapes.noarch 1:1.04-299.el7_9                                      
  perl-Pod-Perldoc.noarch 0:3.20-4.el7                                          
  perl-Pod-Simple.noarch 1:3.28-4.el7                                           
  perl-Pod-Usage.noarch 0:1.63-3.el7                                            
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7                                  
  perl-Socket.x86_64 0:2.010-5.el7                                              
  perl-Storable.x86_64 0:2.45-3.el7                                             
  perl-Text-ParseWords.noarch 0:3.29-4.el7                                      
  perl-Time-HiRes.x86_64 4:1.9725-3.el7                                         
  perl-Time-Local.noarch 0:1.2300-2.el7                                         
  perl-constant.noarch 0:1.27-2.el7                                             
  perl-libs.x86_64 4:5.16.3-299.el7_9                                           
  perl-macros.x86_64 4:5.16.3-299.el7_9                                         
  perl-parent.noarch 1:0.225-244.el7                                            
  perl-podlators.noarch 0:2.5.1-3.el7                                           
  perl-threads.x86_64 0:1.87-4.el7                                              
  perl-threads-shared.x86_64 0:1.43-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.el7                                                     

Complete!
Removing intermediate container ba98100f1fd0
 ---> c79580842faa
Step 6/10 : RUN yum -y install net-tools
 ---> Running in 24ff150b496b
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch         Version                          Repository  Size
================================================================================
Installing:
 net-tools       x86_64       2.0-0.25.20131004git.el7         base       306 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 306 k
Installed size: 917 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : net-tools-2.0-0.25.20131004git.el7.x86_64                    1/1 
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                    1/1 

Installed:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7                                   

Complete!
Removing intermediate container 24ff150b496b
 ---> 1363a8c961a6
Step 7/10 : EXPOSE 80
 ---> Running in 20492594d7e8
Removing intermediate container 20492594d7e8
 ---> 00fec2557bc2
Step 8/10 : CMD echo $MYPATH
 ---> Running in e6784276d43f
Removing intermediate container e6784276d43f
 ---> d15ea1fa5e06
Step 9/10 : CMD echo "---end---"
 ---> Running in 94195fd8c3f4
Removing intermediate container 94195fd8c3f4
 ---> a4b40dca3b65
Step 10/10 : CMD /bin/bash
 ---> Running in ac00ab083e22
Removing intermediate container ac00ab083e22
 ---> 16006c333b6a
Successfully built 16006c333b6a
Successfully tagged mycentos:0.1
[root@ecs-214025 dockerfile]# 

测试运行

[root@ecs-214025 dockerfile]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
mycentos              0.1       16006c333b6a   8 minutes ago    612MB
<none>                <none>    64c28bbdf9b3   29 minutes ago   231MB
zhyq/centos           1.0       f5a290dd6158   2 days ago       231MB
tomcat02              1.0       e843b1f37600   2 days ago       485MB
mysql                 5.7       efa50097efbd   7 days ago       462MB
nginx                 latest    55f4b40fe486   12 days ago      142MB
mysql                 latest    968083d5be36   12 days ago      524MB
tomcat                latest    4813a0e5f815   3 weeks ago      480MB
tomcat                9.0       bfb414f2cf9e   3 weeks ago      480MB
portainer/portainer   latest    12b0b8dced14   8 weeks ago      75.4MB
hello-world           latest    feb5d9fea6a5   9 months ago     13.3kB
centos                7         eeb6ee3f44bd   9 months ago     204MB
centos                latest    5d0da3dc9764   9 months ago     231MB
elasticsearch         7.6.2     f29a1ee41030   2 years ago      791MB
[root@ecs-214025 dockerfile]# docker run -it mycentos:0.1
[root@07c314ec28e9 local]# pwd
/usr/local
[root@07c314ec28e9 local]# vim test
[root@07c314ec28e9 local]# cat test
test vim
[root@07c314ec28e9 local]# 

docker history 查看镜像变更历史

:::info
docker history 查看镜像变更历史
可以学习镜像是怎么做的
:::

[root@ecs-214025 dockerfile]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
mycentos              0.1       16006c333b6a   21 minutes ago   612MB
<none>                <none>    64c28bbdf9b3   41 minutes ago   231MB
zhyq/centos           1.0       f5a290dd6158   2 days ago       231MB
tomcat02              1.0       e843b1f37600   2 days ago       485MB
mysql                 5.7       efa50097efbd   7 days ago       462MB
nginx                 latest    55f4b40fe486   12 days ago      142MB
mysql                 latest    968083d5be36   12 days ago      524MB
tomcat                latest    4813a0e5f815   3 weeks ago      480MB
tomcat                9.0       bfb414f2cf9e   3 weeks ago      480MB
portainer/portainer   latest    12b0b8dced14   8 weeks ago      75.4MB
hello-world           latest    feb5d9fea6a5   9 months ago     13.3kB
centos                7         eeb6ee3f44bd   9 months ago     204MB
centos                latest    5d0da3dc9764   9 months ago     231MB
elasticsearch         7.6.2     f29a1ee41030   2 years ago      791MB
[root@ecs-214025 dockerfile]# docker history 16006c333b6a
IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
16006c333b6a   21 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "/bin…   0B        
a4b40dca3b65   21 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B        
d15ea1fa5e06   21 minutes ago   /bin/sh -c #(nop)  CMD ["/bin/sh" "-c" "echo…   0B        
00fec2557bc2   21 minutes ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
1363a8c961a6   21 minutes ago   /bin/sh -c yum -y install net-tools             177MB     
c79580842faa   21 minutes ago   /bin/sh -c yum -y install vim                   232MB     
b79aa9b42c1b   22 minutes ago   /bin/sh -c #(nop) WORKDIR /usr/local            0B        
b8a05fb667b6   22 minutes ago   /bin/sh -c #(nop)  ENV MYPATH=/usr/local        0B        
71997e6af231   22 minutes ago   /bin/sh -c #(nop)  MAINTAINER zhyq<wl3pbzhyq…   0B        
eeb6ee3f44bd   9 months ago     /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B        
<missing>      9 months ago     /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        
<missing>      9 months ago     /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4…   204MB     
[root@ecs-214025 dockerfile]# docker history efa50097efbd
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
efa50097efbd   7 days ago    /bin/sh -c #(nop)  CMD ["mysqld"]               0B        
<missing>      7 days ago    /bin/sh -c #(nop)  EXPOSE 3306 33060            0B        
<missing>      7 days ago    /bin/sh -c #(nop)  ENTRYPOINT ["docker-entry…   0B        
<missing>      7 days ago    /bin/sh -c ln -s usr/local/bin/docker-entryp…   34B       
<missing>      7 days ago    /bin/sh -c #(nop) COPY file:d27cf504fa76fb5a…   13.6kB    
<missing>      7 days ago    /bin/sh -c #(nop)  VOLUME [/var/lib/mysql]      0B        
<missing>      7 days ago    /bin/sh -c {   echo mysql-community-server m…   325MB     
<missing>      7 days ago    /bin/sh -c echo 'deb [ signed-by=/etc/apt/ke…   97B       
<missing>      7 days ago    /bin/sh -c #(nop)  ENV MYSQL_VERSION=5.7.38-…   0B        
<missing>      7 days ago    /bin/sh -c #(nop)  ENV MYSQL_MAJOR=5.7          0B        
<missing>      7 days ago    /bin/sh -c set -eux;  key='859BE8D7C586F5384…   2.29kB    
<missing>      7 days ago    /bin/sh -c set -eux;  apt-get update;  apt-g…   53.7MB    
<missing>      12 days ago   /bin/sh -c mkdir /docker-entrypoint-initdb.d    0B        
<missing>      12 days ago   /bin/sh -c set -eux;  savedAptMark="$(apt-ma…   4.06MB    
<missing>      12 days ago   /bin/sh -c #(nop)  ENV GOSU_VERSION=1.14        0B        
<missing>      12 days ago   /bin/sh -c apt-get update && apt-get install…   9.34MB    
<missing>      12 days ago   /bin/sh -c groupadd -r mysql && useradd -r -…   329kB     
<missing>      12 days ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      12 days ago   /bin/sh -c #(nop) ADD file:0ae121f9805d31a4a…   69.3MB    
[root@ecs-214025 dockerfile]# docker history 55f4b40fe486
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
55f4b40fe486   12 days ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B        
<missing>      12 days ago   /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0B        
<missing>      12 days ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
<missing>      12 days ago   /bin/sh -c #(nop)  ENTRYPOINT ["/docker-entr…   0B        
<missing>      12 days ago   /bin/sh -c #(nop) COPY file:09a214a3e07c919a…   4.61kB    
<missing>      12 days ago   /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7…   1.04kB    
<missing>      12 days ago   /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0…   1.96kB    
<missing>      12 days ago   /bin/sh -c #(nop) COPY file:65504f71f5855ca0…   1.2kB     
<missing>      12 days ago   /bin/sh -c set -x     && addgroup --system -…   61.1MB    
<missing>      12 days ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~bullseye   0B        
<missing>      12 days ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.7.5        0B        
<missing>      12 days ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.23.0     0B        
<missing>      12 days ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B        
<missing>      12 days ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      12 days ago   /bin/sh -c #(nop) ADD file:8adbbab04d6f84cd8…   80.4MB    
[root@ecs-214025 dockerfile]# 

CMD和ENTRYPOINT的区别

image.png

测试CMD

[root@ecs-214025 dockerfile]# vim dockerfile-cmd-test

FROM centos:7
CMD ["ls","-a"]

[root@ecs-214025 dockerfile]# cat dockerfile-cmd-test 
FROM centos:7
CMD ["ls","-a"]

[root@ecs-214025 dockerfile]# 

[root@ecs-214025 dockerfile]# docker build -f dockerfile-cmd-test -t cmdtest .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM centos:7
 ---> eeb6ee3f44bd
Step 2/2 : CMD ["ls","-a"]
 ---> Running in 7e534da18f19
Removing intermediate container 7e534da18f19
 ---> 6bcf5437dc08
Successfully built 6bcf5437dc08
Successfully tagged cmdtest:latest
[root@ecs-214025 dockerfile]# 
[root@ecs-214025 dockerfile]# docker run 6bcf5437dc08
.
..
.dockerenv
anaconda-post.log
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
[root@ecs-214025 dockerfile]# 

image.png

[root@ecs-214025 dockerfile]# docker run 6bcf5437dc08 -l
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "-l": executable file not found in $PATH: unknown.
[root@ecs-214025 dockerfile]# docker run 6bcf5437dc08 ls -al
total 64
drwxr-xr-x   1 root root  4096 Jul  5 15:53 .
drwxr-xr-x   1 root root  4096 Jul  5 15:53 ..
-rwxr-xr-x   1 root root     0 Jul  5 15:53 .dockerenv
-rw-r--r--   1 root root 12114 Nov 13  2020 anaconda-post.log
lrwxrwxrwx   1 root root     7 Nov 13  2020 bin -> usr/bin
drwxr-xr-x   5 root root   340 Jul  5 15:53 dev
drwxr-xr-x   1 root root  4096 Jul  5 15:53 etc
drwxr-xr-x   2 root root  4096 Apr 11  2018 home
lrwxrwxrwx   1 root root     7 Nov 13  2020 lib -> usr/lib
lrwxrwxrwx   1 root root     9 Nov 13  2020 lib64 -> usr/lib64
drwxr-xr-x   2 root root  4096 Apr 11  2018 media
drwxr-xr-x   2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x   2 root root  4096 Apr 11  2018 opt
dr-xr-xr-x 103 root root     0 Jul  5 15:53 proc
dr-xr-x---   2 root root  4096 Nov 13  2020 root
drwxr-xr-x  11 root root  4096 Nov 13  2020 run
lrwxrwxrwx   1 root root     8 Nov 13  2020 sbin -> usr/sbin
drwxr-xr-x   2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Jun  5 08:56 sys
drwxrwxrwt   7 root root  4096 Nov 13  2020 tmp
drwxr-xr-x  13 root root  4096 Nov 13  2020 usr
drwxr-xr-x  18 root root  4096 Nov 13  2020 var
[root@ecs-214025 dockerfile]# 

测试ENTRYPOINT

[root@ecs-214025 dockerfile]# vim dockerfile-entrypoint-test
[root@ecs-214025 dockerfile]# cat dockerfile-entrypoint-test 
FROM centos:7
ENTRYPOINT ["ls","-a"]

[root@ecs-214025 dockerfile]# docker build -f dockerfile-entrypoint-test -t entrypointtest .
Sending build context to Docker daemon  4.096kB
Step 1/2 : FROM centos:7
 ---> eeb6ee3f44bd
Step 2/2 : ENTRYPOINT ["ls","-a"]
 ---> Running in 9333ed4489fd
Removing intermediate container 9333ed4489fd
 ---> a78d6fe6f56c
Successfully built a78d6fe6f56c
Successfully tagged entrypointtest:latest
[root@ecs-214025 dockerfile]# docker run a78d6fe6f56c
.
..
.dockerenv
anaconda-post.log
bin
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
[root@ecs-214025 dockerfile]# docker run a78d6fe6f56c -l
total 64
drwxr-xr-x   1 root root  4096 Jul  5 16:02 .
drwxr-xr-x   1 root root  4096 Jul  5 16:02 ..
-rwxr-xr-x   1 root root     0 Jul  5 16:02 .dockerenv
-rw-r--r--   1 root root 12114 Nov 13  2020 anaconda-post.log
lrwxrwxrwx   1 root root     7 Nov 13  2020 bin -> usr/bin
drwxr-xr-x   5 root root   340 Jul  5 16:02 dev
drwxr-xr-x   1 root root  4096 Jul  5 16:02 etc
drwxr-xr-x   2 root root  4096 Apr 11  2018 home
lrwxrwxrwx   1 root root     7 Nov 13  2020 lib -> usr/lib
lrwxrwxrwx   1 root root     9 Nov 13  2020 lib64 -> usr/lib64
drwxr-xr-x   2 root root  4096 Apr 11  2018 media
drwxr-xr-x   2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x   2 root root  4096 Apr 11  2018 opt
dr-xr-xr-x 104 root root     0 Jul  5 16:02 proc
dr-xr-x---   2 root root  4096 Nov 13  2020 root
drwxr-xr-x  11 root root  4096 Nov 13  2020 run
lrwxrwxrwx   1 root root     8 Nov 13  2020 sbin -> usr/sbin
drwxr-xr-x   2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x  13 root root     0 Jun  5 08:56 sys
drwxrwxrwt   7 root root  4096 Nov 13  2020 tmp
drwxr-xr-x  13 root root  4096 Nov 13  2020 usr
drwxr-xr-x  18 root root  4096 Nov 13  2020 var
[root@ecs-214025 dockerfile]# 

posted @   清风(学习-踏实)  阅读(224)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
历史上的今天:
2021-07-11 080_Mybatis缓存
2021-07-11 070_Mybatis动态SQL
2021-07-11 060_Mybatis结果映射(多对一和一对多)
2021-07-11 050_Lombok
2021-07-11 040_Mybatis注解开发
2021-07-11 030_Mybatis日志和分页
2021-07-11 020_Mybatis配置解析
点击右上角即可分享
微信分享提示