build
docker build
Builds an image from a Dockerfile and a build context. In Docker 23+ this invokes BuildKit by default and supports multi-platform, secrets, and cache mounts.
docker build [OPTIONS] PATH | URL | - Common flags
| Flag | Purpose |
|---|---|
| -t, --tag | Name and optionally tag the resulting image (name:tag) |
| -f, --file | Path to Dockerfile (default: PATH/Dockerfile) |
| --build-arg | Pass a build-time variable to ARG instructions |
| --no-cache | Skip the layer cache and rebuild every step |
| --platform | Target platform (e.g., linux/amd64,linux/arm64) |
| --target | Build a specific stage in a multi-stage Dockerfile |
| --secret | Expose a secret to the build without baking it into layers |
Examples
docker build -t myapp:1.0 . Standard build from current directory
docker build -f Dockerfile.prod --target runtime -t myapp:prod . Build a named stage from a custom Dockerfile
docker build --platform linux/amd64,linux/arm64 -t user/img:latest --push . Multi-arch build (requires buildx driver)
docker build --secret id=npmrc,src=$HOME/.npmrc -t myapp . Use a build secret safely
Gotcha
Multi-platform builds require a buildx builder with a supported driver — the default docker driver only builds for the host arch. Sending huge build contexts is slow; use .dockerignore aggressively.
Related commands
docker images
Lists images stored in the local image store with their repository, tag, ID, and size. Alias for docker image ls.
docker tag
Creates a new tag (alias) that refers to an existing image. Tagging is required before pushing to a registry whose hostname is not Docker Hub.
docker push
Uploads a local image or repository to a container registry. The image must be tagged with the registry hostname and repository path before pushing.
docker compose
Manages multi-container applications defined in a compose.yaml file. This is the Compose V2 plugin invoked via 'docker compose' (space); the legacy hyphenated 'docker-compose' binary is deprecated.
← All Docker commands · Docker vs Kubernetes · Docker vs VMs