Docker(12)ONBUILD命令案例

2021-09-27 10:01:45 字數 2518 閱讀 3694

onbuild:當構建乙個被繼承的dockerfile時執行的命令,父映象在被子映象繼承後父映象的onbuild被觸發。可以把onbuid理解為乙個觸發器。

[root@t-docker cmd]# cat dockerfile2 

from centos

run yum -y install curl

entrypoint ["curl","-s",""]

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",""]

---> 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",""]

[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",""]

---> running in beff0a4f1b82

removing intermediate container beff0a4f1b82

---> 68d373aea823

successfully built 68d373aea823

successfully tagged myip_son:latest

上面看到在構建dockerfile3時輸出了# executing 1 build trigger這句話。說明子映象繼承父映象時,父映象觸發了相應的動作。 

CentOS下Docker安裝ping命令

說明 docker容器裡,如果我們想測試兩個容器是否建立關係,我們可以用ping來測試。在預設情況下,docker的centenos映象由於做了精簡,去掉了ping命令,此時需要我們自己安裝 執行一下命令,這時會提示沒有找到ping命令 root localhost docker exec it t...

Jenkins容器無法執行docker命令

先看下問題,進入jenkins容器,執行docker命令,無法執行,如下報錯 背景最近想用gitlab jenkins實現持續部署 通過hook觸發jerkins執行job 構建打包 部署,但是執行過程出現報錯 如下圖 於是乎在容器裡面嘗試執行docker命令,出現了如標題問題。如何解決 網上 je...

Docker學習筆記 1 2 Docker元件

docker的核心元件包括 docker是乙個客戶端 伺服器 c s 架構的程式。docker客戶端只需向伺服器或守護程序發出請求,伺服器或守護程序將完成所有工作並返回結果。docker守護程序又是也稱為docker引擎。docker提供了乙個命令列工具docker以及一整套restful api來...