Docker Build

Build images fast with BuildKit, tags, build args, and cache.

  • docker build
  • buildkit
  • build arg
  • dockerignore
  • multi-stage

Docker Build

Build images fast with BuildKit, tags, build args, and cache.

Commands

CommandWhat it does
docker build -t app:v1 .Build with a tag from current dir
docker build --target prod -t app:v1 .Build one multi-stage target
docker build --build-arg VERSION=1.3 .Pass a build-time variable
docker build --no-cache -t app:v1 .Force a clean rebuild
docker history app:v1See layer sizes to find bloat

Example

DOCKER_BUILDKIT=1 docker build --target prod -t registry/app:v1.3 .
docker history registry/app:v1.3 | head

FAQ

Why is my build slow?

Large contexts: add a .dockerignore (node_modules, .git) so the daemon receives kilobytes, not gigabytes.

How do build args differ from env?

ARG exists only at build time; use ENV (or --env at run) for runtime configuration.

الأسئلة الشائعة

Why is my build slow?
Large contexts: add a .dockerignore (node_modules, .git) so the daemon receives kilobytes, not gigabytes.
How do build args differ from env?
ARG exists only at build time; use ENV (or --env at run) for runtime configuration.

Docker