Questions about Dockerfile

Hi I have a few questions I would like to ask:

  1. I am confused about ENV instruction are they like packages for your container for example I have a container thats running python and I install python packages like numpy, pandas etc. Are these the environmental variables? Or are environmental variables just any variable that has a set value?

  2. I know that the ONBUILD instruction is used to create an environment where external pieces of code can be added to on of the running image and could be used to create a new image on top of the old image. How would you be able to use it? Can I get an example of the ONBUILD instructs use within the Dockerfile?

  3. In multi stage builds that use two builds you can copy the binary outputs of the first build and place it in the second build. That is the best practice as the OS from the previous build will not be copied thus making total images size very small right?

#1. Its an environement variable.

#2. Afair, the ONBUILD instruction results in lazy execution of the command itself. Instead of executing it while building the image itself, it will execute the ONBUILD instruction when another Dockerfile that uses such an image as base image is build. This way you can force standard behavior, without actually polluting the base image itself. The official documentation has an example at the bottom of the ONBUILD section. I don’t like ONBUILD as I prefere explicit designed Dockerfiles (=without inherited surprises).

#3. it depends. If you need to install build time dependencies that are not required to run the image, it makes sense to use multi stage build and build everything in the first stage and then just copy over the resulting artifacts.