VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
  • 容器技术之Dockerfile(三)(3)

  提示:可以看到基于我们写的dockerfile构建的镜像已经成功运行为容器,并且标记为healthy;接下来我们进入容器把ok.html干掉,然后在看看容器是否标记为不健康状态?

  提示:从上面的信息可以看到我们把ok.html移除后,容器状态就变成不健康状态了;我们再把ok.html还原到原有位置,看看容器是否会从不健康转换为健康呢?

  提示:可以看到把ok.html还原到/var/www/html/目录后,容器从不健康状态变为了健康状态;

  3、SHELL:该指令用于指定默认shell,该指令开始到下一个SHELL中间的命令都是SHELL指定的shell 运行,所以SHELL指令在dockerfile中可出现多次,后面的SHELL指令指定的shell会覆盖前面所有SHELL指令指定的shell;默认在Linux上是["/bin/sh","-c"]在Windows上述["cmd","/s","/c"];SHELL指令必须是以json数组的格式定义;语法SHELL ["executable", "parameters"];

  4、STOPSIGNAL:该指令用于定义停止容器的信号;默认停止容器是15号信号 SIGTERM;语法STOPSIGNAL signal

  5、ONBUILD:该指令用于在Dockerfile中定义一个触发器;Dockerfile用于build映像文件,此映像文件亦可作为base image被另一个Dockerfile用作FROM指令的参数,并以之构建新的映像文件;在后面的这个Dockerfile中的FROM指令在build过程中被执行时,将会“触发”创建其base image的Dockerfile文件中的ONBUILD指令定义的触发器;用法格式ONBUILD <INSTRUCTION>;尽管任何指令都可注册成为触发器指令,但ONBUILD不能自我嵌套,且不会触发FROM和MAINTAINER指令;使用包含ONBUILD指令的Dockerfile构建的镜像应该使用特殊的标签,例如ruby:2.0-onbuild;在ONBUILD指令中使用ADD或COPY指令应该格外小心,因为新构建过程的上下文在缺少指定的源文件时会失败;

  示例:

1
2
3
4
5
6
7
8
9
10
11
[root@node1 test]# cat Dockerfile
FROM centos:7
 
LABEL maintainer="qiuhom <qiuhom@linux-1874.com>"
 
ONBUILD RUN yum install -y httpd
 
 
 
 
[root@node1 test]#

  提示:以上dockerfile表示在本次构建镜像中不运行yum install -y httpd这条命令,而是在后面的dockerfile中以本dockerfile制作的进行作为基础继续时,yum install -y httpd这条命令就会被触发执行;简单讲onbuild就是指定dockerfile指令延迟执行;这里一定要记住一点onbuild指令后面一定是跟的是dockerfile指令;

  验证:将上面的dockerfile编译镜像,看看yum install -y httpd 是否执行了?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@node1 test]# docker build . -t test:v1.5
Sending build context to Docker daemon  1.052MB
Step 1/3 : FROM centos:7
 ---> b5b4d78bc90c
Step 2/3 : LABEL maintainer="qiuhom <qiuhom@linux-1874.com>"
 ---> Using cache
 ---> d31363b96f38
Step 3/3 : ONBUILD RUN yum install -y httpd
 ---> Running in d3601fa1c3b7
Removing intermediate container d3601fa1c3b7
 ---> 370e3a843c3c
Successfully built 370e3a843c3c
Successfully tagged test:v1.5
[root@node1 test]#

  提示:可以看到yum install -y httpd 这条命令并没有执行;

  验证:将我们上面制作好的镜像作为基础镜像,再来制作其他镜像,看看yum install -y httpd 被执行?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
[root@node1 aaa]# pwd
/root/test/aaa
[root@node1 aaa]# ls
Dockerfile
[root@node1 aaa]# cat Dockerfile
FROM test:v1.5
 
LABEL maintainer="qiuhom <admin@admin.com>"
[root@node1 aaa]# docker build . -t myweb:v1
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM test:v1.5
# Executing 1 build trigger
 ---> Running in cf93e9f03e89
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.huaweicloud.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package             Arch          Version                    Repository   Size
================================================================================
Installing:
 httpd               x86_64        2.4.6-93.el7.centos        base        2.7 M
Installing for dependencies:
 apr                 x86_64        1.4.8-5.el7                base        103 k
 apr-util            x86_64        1.5.2-6.el7                base         92 k
 centos-logos        noarch        70.0.6-3.el7.centos        base         21 M
 httpd-tools         x86_64        2.4.6-93.el7.centos        base         92 k
 mailcap             noarch        2.1.41-2.el7               base         31 k
 
Transaction Summary
================================================================================
Install  1 Package (+5 Dependent packages)
 
Total download size: 24 M
Installed size: 32 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/apr-1.4.8-5.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for apr-1.4.8-5.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total                                              7.2 MB/s |  24 MB  00:03    
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-8.2003.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 : apr-1.4.8-5.el7.x86_64                                       1/6
  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/6
  Installing : httpd-tools-2.4.6-93.el7.centos.x86_64                       3/6
  Installing : centos-logos-70.0.6-3.el7.centos.noarch                      4/6
  Installing : mailcap-2.1.41-2.el7.noarch                                  5/6
  Installing : httpd-2.4.6-93.el7.centos.x86_64                             6/6
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  1/6
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  2/6
  Verifying  : httpd-2.4.6-93.el7.centos.x86_64                             3/6
  Verifying  : apr-1.4.8-5.el7.x86_64                                       4/6
  Verifying  : httpd-tools-2.4.6-93.el7.centos.x86_64                       5/6
  Verifying  : centos-logos-70.0.6-3.el7.centos.noarch                      6/6
 
Installed:
  httpd.x86_64 0:2.4.6-93.el7.centos                                           
 
Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7                                                     
  apr-util.x86_64 0:1.5.2-6.el7                                                
  centos-logos.noarch 0:70.0.6-3.el7.centos                                    
  httpd-tools.x86_64 0:2.4.6-93.el7.centos                                     
  mailcap.noarch 0:2.1.41-2.el7                                                
 
Complete!
Removing intermediate container cf93e9f03e89
 ---> a89914bda4b5
Step 2/2 : LABEL maintainer="qiuhom <admin@admin.com>"
 ---> Running in e175e0542b5e
Removing intermediate container e175e0542b5e
 ---> 4f406abeaab7
Successfully built 4f406abeaab7
Successfully tagged myweb:v1
[root@node1 aaa]#

相关教程