Build a Docker image from a Dockerfile.
low risk
docker build creates images from a Dockerfile. The -t flag tags the image. Build context (the path argument) is sent to the Docker daemon — use .dockerignore to exclude unnecessary files and speed up builds.
| Flag | Meaning |
|---|---|
-t --tag | Name and optionally tag the image |
-f --file | Path to Dockerfile |
--no-cache | Build without using cache |
--build-arg | Set build-time variables |
--platform | Target platform (e.g., linux/amd64,linux/arm64) |
docker build -t myapp:v1.2.3 .Build and tag image from current directory · explain & risk-check →docker build --no-cache -t myapp:latest .Force clean build ignoring cache · explain & risk-check →docker build --platform linux/amd64,linux/arm64 -t myapp:latest .Multi-platform build · explain & risk-check →docker build --build-arg ENV=production -t myapp:prod .Pass build argument · explain & risk-check →Order Dockerfile instructions from least to most frequently changing — COPY requirements.txt and RUN pip install before COPY . . — to maximize cache layer reuse and reduce build times.
Reference text is hand-written and may be incomplete — check man docker for your version. Test destructive commands on a non-production system first.