# docker build Command Reference

> Reference for docker build in CI: tag, file, build-arg, target, platform, no-cache, and pull flags for building images from a Dockerfile in pipelines.

Source: https://latchkey.dev/learn/command-reference/docker-build-command-reference  
Updated: 2026-06-26

Build an image from a Dockerfile and build context.

docker build packages a build context plus a Dockerfile into a layered image. In modern Docker it invokes BuildKit by default. The final positional argument is the build context (usually .), not the Dockerfile path.

## Common flags

- `-t, --tag` - name and optionally tag the image as name:tag (repeatable)
- `-f, --file` - path to the Dockerfile (default ./Dockerfile)
- `--build-arg` - pass a build-time ARG value, e.g. NODE_ENV=production
- `--target` - build only a named stage in a multi-stage Dockerfile
- `--platform` - target platform, e.g. linux/amd64
- `--no-cache` - ignore the layer cache and rebuild every step
- `--pull` - always pull a newer version of the base image

## Example

```shell
docker build \
  -t myorg/app:${GITHUB_SHA} \
  -f docker/Dockerfile \
  --build-arg NODE_ENV=production \
  --target runtime \
  --pull \
  .
```

## In CI

Tag with an immutable identifier such as the commit SHA so each build is traceable. Use --pull on scheduled builds to pick up base-image security patches, and --no-cache when you suspect a stale cached layer. Note: a frequent CI failure is "failed to compute cache key: not found" when a COPY path is outside the build context or excluded by .dockerignore.

## FAQ

### docker build Command Reference?

docker build packages a build context plus a Dockerfile into a layered image. In modern Docker it invokes BuildKit by default. The final positional argument is the build context (usually .), not the Dockerfile path.

### In CI?

Tag with an immutable identifier such as the commit SHA so each build is traceable. Use --pull on scheduled builds to pick up base-image security patches, and --no-cache when you suspect a stale cached layer.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
