The ONBUILD instruction is a tool used when creating images that will become the parameter to the FROM instructions in another Dockerfile. The ONBUILD instruction just adds metadata to your image, specifically a trigger that is stored in the image and not otherwise used. However, that metadata trigger does get used when your image is supplied as the parameter in the FROM command of another Dockerfile. Here is the ONBUILD instruction syntax:
# ONBUILD instruction syntax
ONBUILD [INSTRUCTION]
The ONBUILD instruction is kind of like a Docker time machine used to send instructions into the future. (You might laugh if you knew how many times I just typed Doctor time machine!) Let's demonstrate the use of the ONBUILD instruction with a simple example. First, we will build an image named my-base using the following Dockerfile:
# my-base Dockerfile
FROM alpine...