Docker(六):DockerFile案例3

ONBUILD 镜像案例

类似触发器,当构建一个被继承的DockerFile时运行命令,父镜像在被子镜像继承后父镜像的ONBUILD被触发

[root@localhost mydocker]# ll
总用量 16
-rw-r--r--. 1 root root 144 10月 11 15:01 Dockerfile
-rw-r--r--. 1 root root 238 10月 12 15:05 Dockerfile2
-rw-r--r--. 1 root root  72 10月 13 15:05 Dockerfile3
-rw-r--r--. 1 root root  77 10月 13 15:27 Dockerfile4
[root@localhost mydocker]# vim Dockerfile4
[root@localhost mydocker]# cat Dockerfile4
FROM centos
RUN yum install -y curl
ENTRYPOINT ["curl","-s","http://ip.cn" ]
ONBUILD RUN echo "father images onbuild =============================="

创建父镜像

[root@localhost mydocker]# docker build -f /mydocker/Dockerfile4 -t myip_father .
Sending build context to Docker daemon   5.12kB
Step 1/4 : FROM centos
 ---> 75835a67d134
Step 2/4 : RUN yum install -y curl
 ---> Using cache
 ---> 1bd5b74f7407
Step 3/4 : ENTRYPOINT ["curl","-s","http://ip.cn" ]
 ---> Using cache
 ---> dcbb4656e640
Step 4/4 : ONBUILD RUN echo "father images onbuild =============================="
 ---> Running in d241b6abf522
Removing intermediate container d241b6abf522
 ---> 2c22e721607a
Successfully built 2c22e721607a
Successfully tagged myip_father:latest

[root@localhost ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED              SIZE
myip_father              latest              2c22e721607a        About a minute ago   299MB
myip2                    latest              dcbb4656e640        18 minutes ago       299MB
myip                     latest              9e3c14f76b1d        37 minutes ago       299MB
mycentos                 1.0                 c2d4f6acb9af        23 hours ago         455MB
zhaoyoung/nodocstomcat   1.0                 84498728984a        2 days ago           463MB
centos                   latest              75835a67d134        3 days ago           200MB
tomcat                   latest              41a54fe1f79d        4 weeks ago          463MB
hello-world              latest              4ab4c602aa5e        5 weeks ago          1.84kB

创建子镜像DockerFile

[root@localhost mydocker]# cp Dockerfile3 Dockerfile5
[root@localhost mydocker]# vim Dockerfile5
[root@localhost mydocker]# cat Dockerfile5
FROM myip_father
RUN yum install -y curl
CMD ["curl","-s","http://ip.cn" ]

创建子镜像
可以看到 # Executing 1 build trigger 执行了一个触发器

[root@localhost mydocker]# docker build -f /mydocker/Dockerfile5 -t myip_son .
Sending build context to Docker daemon  6.144kB
Step 1/3 : FROM myip_father
# Executing 1 build trigger
 ---> Running in 4b5f9fcbd7c2
father images onbuild ==============================
Removing intermediate container 4b5f9fcbd7c2
 ---> 7f27cd2976b3
Step 2/3 : RUN yum install -y curl
 ---> Running in c0321245bce2
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.cn99.com
Package curl-7.29.0-46.el7.x86_64 already installed and latest version
Nothing to do
Removing intermediate container c0321245bce2
 ---> 4894e3bc58fd
Step 3/3 : CMD ["curl","-s","http://ip.cn" ]
 ---> Running in bdf691d69518
Removing intermediate container bdf691d69518
 ---> 6c9507aea358
Successfully built 6c9507aea358
Successfully tagged myip_son:latest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值