ONBUILD案例
1.基于centos:7镜像,创建一个可以查IP的镜像
#Dockerfile08
FROM centos:7
MAINTAINER yz<yz@126.com>
RUN yum -y install curl
ENTRYPOINT ["curl","-s","https://www.cip.cc/"]
ONBUILD RUN echo "==images onbuild=="
发现构建父镜像时,ONBUILD指令不会执行
2.基于刚才创建的镜像创建子镜像
[root@aaa ~/mydocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ip_father latest fc0f2819e2ee 7 minutes ago 290 MB
#Dockerfile09
FROM ip_father
RUN yum -y install curl
ENTRYPOINT ["curl","-s","https://www.cip.cc/"]
子镜像构建时执行了ONBUILD指令
3.基于子镜像创建镜像
[root@aaa ~/mydocker]# vim Dockerfile10
FRON ip_son
yum -y install curl
RUN ["curl","-s","https://www.cip.cc/"]
发现已经没有了ONBUILD指令
结论:ONBUILD指令仅适用于从当前镜像创建子镜像,而不适用于“孙子”镜像,也就是ONBUILD指令不会继承