Generate a .dockerignore that keeps your Docker builds fast, your images small and your secrets out of them. Pick your stacks — Node, Python, Go, Java, PHP, Rust, .NET or a front-end build — and get a file that always excludes .git, .env files and keys, with each rule explained. Add your own lines and download it. It's free, runs in your browser, and nothing is uploaded.
| Pattern | .gitignore | .dockerignore |
|---|---|---|
| node_modules | Any depth | Top level only |
| **/node_modules | Any depth | Any depth |
| dir/ | Directory | Trailing slash ignored |
| !keep.txt | Re-include | Re-include |
Without one, the whole folder — including .git, node_modules and .env — is sent to Docker and can be copied into the image by COPY . .
Not directly. .dockerignore matches from the build-context root, so node_modules only matches the top level; use **/node_modules for nested folders.
It's safe to — Docker still reads it — and it keeps it out of the image.
Add a line starting with !, like !.env.example, after the rule that excludes it.
No. The file is generated in your browser.
Everything in the build context is sent to the Docker daemon before the build starts, and COPY . . will copy all of it into the image. A good .dockerignore therefore does three jobs: it keeps builds fast by not sending large folders such as .git or node_modules, keeps images small and reproducible by excluding locally built artifacts that the Dockerfile rebuilds anyway, and keeps secrets out — .env files, private keys and certificates would otherwise end up in an image layer that anyone with the image can read. A base set covering version control, secrets, logs, editor files, documentation and the Docker files themselves is always included, with an exception that keeps .env.example. Stack presets add each ecosystem's dependency folders, caches and build output, and rules shared between presets are written once. Patterns use .dockerignore's own matching, which is anchored at the context root, so nested folders are written with **/ — the most common mistake when copying a .gitignore. Each rule can carry a short comment explaining why it's there.