liveBook · Manning

Dockerignore

As explained in Learn Docker in a Month of Lunches, Second Edition

A Docker build configuration file that specifies files and directories to exclude from the build context.

A .dockerignore file lists files and directories Docker should exclude from the build context. Excluded content is not sent to the Docker Engine, reducing transfer time and potentially shrinking the resulting image. section 17.1

Use .dockerignore when:

  • A Dockerfile uses COPY . . but the context contains documentation, images, or other unnecessary files. section 17.1
  • A nested project makes precise COPY patterns awkward or convoluted. section 17.1
  • Local build output must not be copied into a Docker multi-stage build. section 17.1

Reduce the build context

Create .dockerignore in the build directory and exclude the docs folder. A no-cache build with the original context sends 2 MB; the ignored context sends about 190 bytes, and the resulting v4 image is 2 MB smaller.

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains the file’s role, practical trade-offs, and measured build effects, but does not detail pattern syntax.
Examples
Uses a docs folder, a 2 MB whale picture, no-cache builds, image tags, and context-size comparison.
What it assumes
Assumes familiarity with Dockerfiles, COPY, image builds, and build contexts.
What you can do after
Operate/configure Docker builds by excluding unused files and verifying smaller contexts and images.
How it connects
Connects .dockerignore with Dockerfile COPY commands, Docker build context, BuildKit, multi-stage builds, and Git’s .gitignore format.

Also explained in

Compare how 4 books explain dockerignore →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.