Please see these pages for more information:
Docker CLI: docker build (build an image from a Dockerfile)
https://docs.docker.com/engine/reference/commandline/build/
https://docs.docker.com/develop/develop-images/multistage-build/
The '
docker build' command has the following syntax:
Let's use this Dockerfile:
To build an image from a Dockerfile:
The option '
-t IMAGE_NAME:IMAGE_TAG' instruct Docker to create an image with the specified name (
ubuntu-nginx) and tag (
20.04).
The character '
.' specifies the current directory and it represents the path where Docker will look for any files and directories handled in the Dockerfile.
By default, Docker will look for a Dockerfile with the name '
Dockerfile' in the current directory.
You can add a ".dockerignore" file where you can list files and directories that you want to be excluded when building the image.
The build command produces the following output:
In this case it's the first time the image is built.
All the steps are executed and no cache was used by Docker.