docker build

Build an image from a Dockerfile. The build context is typically the directory containing the Dockerfile.

Syntax

docker build [OPTIONS] PATH | URL | -

Examples

Example 1
docker build -t myapp:latest .

Build from current directory and tag as myapp:latest.

Example 2
docker build -f Dockerfile.prod -t myapp:v1.2 .

Use a non-default Dockerfile and tag with version.

Example 3
docker build --no-cache -t myapp .

Build without using cache (full rebuild).

Common flags

FlagDescription
-t, --tagName and optionally tag (name:tag)
-f, --filePath to Dockerfile
--no-cacheDo not use cache when building
--build-argSet build-time variable

Tips & best practices

Related commands

View full Docker cheatsheet →