A docker layer is a change on an image causing the previous image to change. You can
look at it as a step in your docker build that is doing something that adjusts
your docker image. The only instructions that create layers are RUN, COPY, and
ADD. Wherever possible those commands should be combined:
A faster Docker build can also be assisted by combining commands even when they
don’t create additional layers. For example combining ENV docker commands:
Using multi stage builds can also make your build faster and reduce the docker
image size as well. This reduces the size of the final image because it leverages build
cache. Setting up a multi stage build requires Docker version >17.05
you to build out a single Docker separating out steps of the Docker build
into only the final required steps for your image. With the multi stage build
you structure multiple FROM commands to reference the previous Dockerfile build.
If you’re running a chown step it can take quite a long time if your source code
size is large. Also, if you’re copying your source code into your container from
the host it can take a long time as well. Instead you can combine the two steps into one: