.dockerignore generator

Tick what your project contains and copy a .dockerignore. It keeps dependencies, build output, logs and secrets out of the build context, so builds upload less, cache better and do not copy .env files into images.

Separate patterns with spaces or commas, for example docs/ **/*.tmp

Save as .dockerignore next to the Dockerfile, in the root of the build context. Check that nothing your Dockerfile copies is excluded.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Leave Docker and Git files and Secrets ticked: they are useful in almost every project.
  2. Tick your language and, if needed, editors and OS files.
  3. Add your own patterns, for example a folder of test fixtures.
  4. Save the result as .dockerignore in the build context root, usually next to the Dockerfile.

How it works

The chosen lists are combined in a fixed order: Docker and Git, secrets, languages, editors, OS files, then your own patterns. A pattern that already appeared in an earlier group is not repeated, and a group left empty by that is dropped.

Docker matches each line against paths relative to the context root. * matches within one folder, ** matches any number of folders, and ! re-includes files excluded before.

Example

The default choice (Docker and Git, secrets, Node.js, OS files) starts like this:

# Docker and Git
.git
.gitignore
.dockerignore
Dockerfile*
docker-compose*.yml
compose*.yaml
**/*.log

# Secrets
.env
.env.*
!.env.example
**/*.pem
**/*.key

and goes on with **/node_modules, npm and pnpm logs, coverage, dist, **/.DS_Store and **/Thumbs.db.

Tips

  • Excluding node_modules matters for more than speed: dependencies installed on your machine may be built for another system. Install them inside the image instead.
  • If your Dockerfile copies a prebuilt file, such as target/app.jar or dist/, untick that group or add an exception with !.
  • Run docker build --no-cache . after big changes to check that the image still builds without the ignored files.

Frequently asked questions

What does .dockerignore do?

When you run docker build, the folder you name (the build context) is sent to the builder. Files matching .dockerignore are left out of the context, so COPY and ADD cannot copy them and the upload is smaller.

Why do some patterns start with **/?

In .dockerignore a pattern is matched from the root of the build context: node_modules excludes only the top-level folder. **/node_modules matches the folder at any depth, which matters in monorepos.

How do I keep one file that a pattern excludes?

Add a line starting with ! after the pattern, as in .env.* followed by !.env.example. The last matching line decides, so an exception must come after the rule it overrides.

Can I exclude the Dockerfile itself?

Yes. The builder still receives the Dockerfile and .dockerignore because it needs them, but COPY . . will not put them into the image.

Is .dockerignore the same as .gitignore?

The idea is the same, the rules differ: .gitignore patterns without a slash match at any depth, .dockerignore patterns are anchored at the context root. That is why this list writes **/ where a folder can appear anywhere.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.