您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。