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 / Option | Description |
|---|---|
| -t / --tag | Name and optionally a tag in the 'name:tag' format. |
| -f / --file | Name of the Dockerfile (Default is 'PATH/Dockerfile'). |
| --no-cache | Do not use the build cache. Forces a completely fresh build. |
| --build-arg | Set 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?