# .dockerignore

> A file that lists what to leave out when an image is built.

**Field:** Infrastructure  
**Category:** Containers  
**Also known as:** .dockerignore File, Docker Ignore File, dockerignore

## Think of it like

Think of it like a list of things not to pack for a trip.

## Definition

A .dockerignore file lists the files and folders to leave out when building an image. It sits in the top folder of the build. Before a build starts, that folder is sent to the builder, minus whatever this file names. Each line is a pattern, such as *.log for all log files. Leaving out big or secret files makes builds faster and keeps secrets out of the image.

## Example

Emma's project folder holds 900 MB of downloaded packages and a .env file with passwords. Two lines in .dockerignore keep both out of the build.

## Example code

```console
$ cat .dockerignore
node_modules
.env
*.log
.git
```

Four lines keep out the packages, the secrets, the logs and the history.

## Why it matters

Everything not left out is sent to the builder and can end up in the image. That includes passwords.

## Common mistake

Putting it in the wrong folder. It has to sit in the top folder of the build, or nothing is left out.

## Three principles

- **A leave-out list.** One pattern on each line.
- **The top folder.** It sits at the root of the build.
- **Faster and safer.** Less to send and no secrets inside.

## Related terms

- [Dockerfile](https://learn.benibix.com/term/infrastructure/dockerfile)
- [Container Image](https://learn.benibix.com/term/infrastructure/container-image)
- [Multi-Stage Build](https://learn.benibix.com/term/infrastructure/multi-stage-build)
- [.gitignore](https://learn.benibix.com/term/development/gitignore)

![A project folder passes through a .dockerignore filter that drops node_modules and .env. The rest goes into a large build stage holding tools and source code. One arrow carries only the finished app into a small final image.](https://learn.benibix.com/diagrams/inf4-image-builds.svg)

---

Source: https://learn.benibix.com/term/infrastructure/dockerignore
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
