Docker Course
Docker
/
Beginner

docker build

Definition

The CLI command used to create a Docker image from a Dockerfile and a 'build context'.

Explain Like I'm New

Telling the chef to start cooking. You point Docker at the recipe file (Dockerfile) and tell it to begin executing the steps.

Real World Example

You open the terminal in your project folder and type `docker build -t my-app:latest .`. Docker reads the `Dockerfile` in the current folder, executes every `RUN` command, and creates the final image named `my-app:latest`.

Common Use Cases

  • •Creating images
  • •CI/CD pipelines

Crucial Command Flags

Flag / OptionDescription
-t / --tagName and optionally a tag in the 'name:tag' format.
-f / --fileName of the Dockerfile (Default is 'PATH/Dockerfile').
--no-cacheDo not use the build cache. Forces a completely fresh build.
--build-argSet build-time variables (only available during the build process).

Interview Questions

basic

  • What does the `-t` flag stand for in the `docker build` command?

intermediate

  • Why do you almost always see a single period `.` at the absolute end of a `docker build` command?

Flash Cards

Question

What is the -t flag?

Click to reveal answer
Answer

Tag. It allows you to name the image immediately as it is being built (e.g., `-t website:v1`).

Question

Why the period?

Click to reveal answer
Answer

The period represents the 'Build Context'. It tells Docker 'The files you need to copy into the image are located right here in my current folder'.