Dockerfile ONBUILD instruction

I read on the docker documentation how ONBUILD instruction can be used, but it is not clear at all.
Can someone please explain it to me?

  • Trouble running UPNP on Docker
  • Concourse CI Pipeline giving error :- Get net/http: request canceled while waiting for connection
  • Working on a Dockerfile in order to build a WordPress image
  • How to create Dockerfile which installs Python 3 and nltk in a Ubuntu container?
  • Cannot access Google Container Registry from Google Compute Engine
  • How to specify docker image path on command line without editing configuration setting?
  • change bluemix docker default subnet to a different value?
  • Docker can not be installed on CentOS
  • Error while running Jenkins in Docker
  • Add your application to a Docker image
  • Mac host doesn't like Docker container port forwarding
  • Bluemix: service bound to container does not appear in VCAP_SERVICES
  • One Solution collect form web for “Dockerfile ONBUILD instruction”

    The ONBUILD intruction is very useful for automating the build of your chosen software stack.


    The Maven container is designed to compile java programs. Magically all your project’s Dockerfile needs to do is reference the base container containing the ONBUILD intructions:

    FROM maven:3.3-jdk-8-onbuild
    CMD ["java","-jar","/usr/src/app/target/demo-1.0-SNAPSHOT-jar-with-dependencies.jar"]

    The base image’s Dockerfile tells all

    FROM maven:3-jdk-8
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    ONBUILD ADD . /usr/src/app
    ONBUILD RUN mvn install

    There’s a base image that has both Java and Maven installed and a series of instructions to copy files and run Maven.

    The following answer gives a Java example

    • How to build a docker container for a java app
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.