.dockerignore

What is a .dockerignore file?

Tells `docker build` which files to skip when sending the build context to the Docker daemon — the difference between a 50 MB and 2 GB build.

Safe format
Type Code
By Docker Inc.
MIME text/plain

Drop any file to identify it

No upload. No signup. No sending your file halfway across the internet.
We tell you what it is, right here in your browser.

What is it

Before Docker can build an image, it has to send the entire build context — every file in the directory you ran `docker build` from — to the Docker daemon. If that directory contains `node_modules/` (300 MB), `.git/` (50 MB), build artefacts, log files, and your local `.env` with API keys, all of it gets shipped over for the build, even if your Dockerfile never copies them in.

The .dockerignore file lives next to your Dockerfile and lists patterns to exclude from the build context, gitignore-style. A typical .dockerignore: `node_modules`, `.git`, `*.log`, `.env`, `dist`, `build`, `.DS_Store`, `coverage`. The result is faster uploads, smaller cache invalidations (changes in ignored files don't bust your build cache), and fewer secrets accidentally baked into images. If your Dockerfile uses `COPY . /app`, this file is the only thing standing between your Docker image and your `.env` file.

The syntax is largely the same as .gitignore — glob patterns, `!` for re-includes, `#` for comments — but with a few quirks. Path matching is anchored at the build context root (no leading-slash ambiguity), and patterns are evaluated relative to that root. Don't confuse .dockerignore with .gitignore: they serve different purposes, and you almost always want both. The .gitignore protects your repo from junk; the .dockerignore protects your image from bloat and secrets.

Technical details
Full Name
.dockerignore
MIME Type
text/plain
Developer
Docker Inc.
Magic Bytes
N/A
Safety
.dockerignore is a known, safe format.
What opens it
Any text editor
FREE All
VS Code
FREE All
FAQ
Do I need a .dockerignore if my Dockerfile only COPYs specific files?
Yes, you still benefit. Even if your Dockerfile only does `COPY package.json /app`, the entire build context still gets uploaded to the Docker daemon. .dockerignore reduces what gets sent, which speeds up builds and avoids cache invalidations from unrelated file changes.
Can I just use my .gitignore for Docker?
Not directly — Docker doesn't read .gitignore. You can copy its patterns over, but consider adding a few Docker-specific ones: `Dockerfile*` (so your build doesn't include other Dockerfiles), and any local development files that your tests depend on but production doesn't need.
Related formats