Home·Terminal commands

docker build

Packages and runtimes

Usage

docker build -t <name>:<tag> [-f <Dockerfile>] <context>

Builds an image from a Dockerfile; the trailing dot is the build context sent to the daemon, so a fat folder makes builds slow until .dockerignore trims it, and COPY can only see files inside that context.

Common flags

FlagMeaning
-t <name>:<tag>name the image; without it you only get an id
-f <file>use a Dockerfile that is not ./Dockerfile
--no-cacherebuild every layer
--build-arg KEY=valuepass an ARG into the build
--target <stage>stop at one stage of a multi-stage file
--platform linux/amd64build for another architecture
--progress=plainfull log output instead of the collapsed view

Examples

docker build -t myapp:1.0 .

builds from ./Dockerfile with the current folder as context

docker build -f docker/Dockerfile.dev -t myapp:dev .

another Dockerfile, same context

docker build --platform linux/amd64 -t myapp:1.0 .

an x86 image built on an Apple Silicon Mac

The question is always what goes where: inside this project, or on the whole machine.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does docker build do?

Builds an image from a Dockerfile; the trailing dot is the build context sent to the daemon, so a fat folder makes builds slow until .dockerignore trims it, and COPY can only see files inside that context.

Q. How do I type it?

docker build -t <name>:<tag> [-f <Dockerfile>] <context> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man docker. This command sits under Packages and runtimes.

Related commands

man page: man docker-build