这篇文章将为大家详细讲解有关docker中Dockerfile的ONBUILD命令怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
ONBUILD:当构建一个被继承的Dockerfile时运行的命令,父镜像在被子镜像继承后父镜像的onbuild被触发。可以把ONBUID理解为一个触发器。
[root@t-docker CMD]# cat Dockerfile2 from centos RUN yum -y install curl ENTRYPOINT ["curl","-s","http://ip.cn"] ONBUILD RUN echo "father images onbuild -----886" #表示哪个镜像继承了我,我就打出这句话
[root@t-docker CMD]# docker build -f Dockerfile2 -t myip_father . Sending build context to Docker daemon 3.072kB Step 1/4 : from centos ---> 5182e96772bf Step 2/4 : RUN yum -y install curl ---> Using cache ---> a35f6ad9700f Step 3/4 : ENTRYPOINT ["curl","-s","http://ip.cn"] ---> Using cache ---> b772af142e86 Step 4/4 : ONBUILD RUN echo "father images onbuild -----886" #表示哪个镜像继承了我,我就打出这句话。 ---> Running in 8366a71cb8ba Removing intermediate container 8366a71cb8ba ---> 8615f1d828ed Successfully built 8615f1d828ed Successfully tagged myip_father:latest
[root@t-docker CMD]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myip_father latest 8615f1d828ed 28 seconds ago 293MB
[root@t-docker CMD]# cat Dockerfile3 from myip_father RUN yum -y install curl CMD ["curl","-s","http://ip.cn"]
[root@t-docker CMD]# docker build -f Dockerfile3 -t myip_son . Sending build context to Docker daemon 4.096kB Step 1/3 : from myip_father # Executing 1 build trigger ---> Running in c0ec856045b2 father images onbuild -----886 Removing intermediate container c0ec856045b2 ---> 533afe432759 Step 2/3 : RUN yum -y install curl ---> Running in 943e0afa4268 Loaded plugins: fastestmirror, ovl Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.neusoft.edu.cn Package curl-7.29.0-46.el7.x86_64 already installed and latest version Nothing to do Removing intermediate container 943e0afa4268 ---> 54ddf5f440ec Step 3/3 : CMD ["curl","-s","http://ip.cn"] ---> Running in beff0a4f1b82 Removing intermediate container beff0a4f1b82 ---> 68d373aea823 Successfully built 68d373aea823 Successfully tagged myip_son:latest
上面看到在构建Dockerfile3时输出了# Executing 1 build trigger这句话。说明子镜像继承父镜像时,父镜像触发了相应的动作。
关于“docker中Dockerfile的ONBUILD命令怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。