Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the ONBUILD command of Dockerfile in docker

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use the ONBUILD command of Dockerfile in docker. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

ONBUILD: the command that runs when building an inherited Dockerfile, and the parent image is triggered when the parent image is inherited from the quilt image. You can think of ONBUID as a trigger.

[root@t-docker CMD] # cat Dockerfile2 from centosRUN yum-y install curlENTRYPOINT ["curl", "- s", "http://ip.cn"]ONBUILD RUN echo" father images onbuild-886 "# indicates which image inherits from me I'll type this sentence [root@t-docker CMD] # docker build-f Dockerfile2-t myip_father. Sending build context to Docker daemon 3.072kBStep 1ap4: from centos-- > 5182e96772bfStep 2 RUN yum 4: RUN yum-y install curl-- > Using cache-- > a35f6ad9700fStep 3 Using cache 4: ENTRYPOINT ["curl", "- s" "http://ip.cn"]-- > Using cache-- > b772af142e86Step 4 b772af142e86Step 4: ONBUILD RUN echo" father images onbuild-886 "# indicates which image inherits me. That's what I typed. -- > Running in 8366a71cb8baRemoving intermediate container 8366a71cb8ba-- > 8615f1d828edSuccessfully built 8615f1d828edSuccessfully tagged myip_father: latest [root @ t-docker CMD] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmyip_father latest 8615f1d828ed 28 seconds ago 293MB [root@t-docker CMD] # cat Dockerfile3from myip_fatherRUN yum-y install curlCMD ["curl", "- s" "http://ip.cn"][root@t-docker CMD] # docker build-f Dockerfile3-t myip_son .Sending build context to Docker daemon 4.096kBStep 1 build trigger 3: from myip_father# Executing 1 build trigger-- > Running in c0ec856045b2father images onbuild-886Removing intermediate container c0ec856045b2-> 533afe432759Step 2 886Removing intermediate container c0ec856045b2 3: RUN yum-y install curl-- > Running in 943e0afa4268Loaded plugins: fastestmirror OvlLoading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.neusoft.edu.cnPackage curl-7.29.0-46.el7.x86_64 already installed and latest versionNothing to doRemoving intermediate container 943e0afa4268-> 54ddf5f440ecStep 3 CMD 3: CMD ["curl", "- s", "http://ip.cn"]-- > Running in beff0a4f1b82Removing intermediate container beff0a4f1b82-> 68d373aea823Successfully built 68d373aea823Successfully tagged myip_son:latest"

As you can see above, the phrase # Executing 1 build trigger is printed when building Dockerfile3. Indicates that when the child image inherits the parent image, the parent image triggers the corresponding action.

This is the end of this article on "how to use the ONBUILD command of Dockerfile in docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report