docker-build
TLDR
Build an image from Dockerfile
SYNOPSIS
docker build [options] path|url
DESCRIPTION
docker build creates Docker images from a Dockerfile and context (files available during build). The Dockerfile contains instructions for assembling the image layer by layer.
The build context is sent to the Docker daemon, which processes Dockerfile instructions sequentially. Each instruction creates a layer; layers are cached and reused when unchanged, speeding up subsequent builds.
Modern builds use BuildKit (enabled by default in recent Docker versions), providing improved performance, better caching, and features like secrets and SSH forwarding.
PARAMETERS
-t, --tag name:tag
Name and optionally tag the image.-f, --file path
Path to Dockerfile (default: PATH/Dockerfile).--build-arg key=value
Build-time variables.--no-cache
Don't use cache when building.--pull
Always pull newer base image.--target stage
Build specific stage in multi-stage Dockerfile.--platform platform
Target platform (linux/amd64, linux/arm64).--progress type
Progress output: auto, plain, tty.--secret id=secret
Secret to expose to build.--ssh socket
SSH agent socket to expose.-q, --quiet
Suppress build output.--push
Push image after build (buildx).
CAVEATS
Large build contexts slow builds; use .dockerignore to exclude unnecessary files. Layer caching depends on instruction order; put frequently changing instructions last. Multi-platform builds require buildx and may need emulation or cross-compilation setup.
HISTORY
Docker build has been a core Docker feature since the initial release in 2013. BuildKit, a next-generation builder with improved performance and features, was introduced in 2017 and became the default in Docker 23.0 (2023). The buildx plugin extends build capabilities for multi-platform images and advanced build scenarios.
SEE ALSO
docker(1), docker-run(1), dockerfile(5), docker-compose(1)


