Which file to test
Docker uses one ignore file per build. If your Dockerfile has its own ignore file next to it, such as build.Dockerfile.dockerignore, Docker uses that one instead of the root .dockerignore. It doesn't merge the two. Pick the matching option in Effective file and paste only that file.
Which paths to try
Write paths relative to the build context, the folder you pass to docker build, which is usually the project folder. Try the source of each COPY you care about, a file inside each folder you exclude, and each ! exception.
How to read the result
Every path starts as Included. Each matching line flips it to Excluded, or back to Included for a ! line. The last matching line decides, and the trace shows every line that matched along the way.
Ignore the docs folder but keep its README
Example
Rules: docs, then !docs/README.md. Paths: docs/README.md, docs/guide, and src.
docs/README.md is Included by line 2. Its trace shows line 1 as a Parent match, because docs matched the folder it sits in, and line 2 as a Direct match. docs/guide is Excluded by line 1. src matches nothing, so it stays Included.
Why doesn't my .dockerignore pattern match files in subfolders?
Patterns start at the root of the build context. *.log matches app.log but not logs/app.log. To match at any depth, start the pattern with **/.
The same rules, with and without **/
Example
With *.log and node_modules:
app.logandnode_modules/x/index.jsare Excluded.logs/app.logandpackages/web/node_modules/y.jsare Included.
With **/*.log and **/node_modules, all four are Excluded.
This is the biggest difference from .gitignore, where *.log matches in every folder. Docker's own example shows *.md excluding Markdown files at the root only.
How do I ignore everything except a few files?
Start with *, then add a ! line for each thing you want to keep. The order matters, because the last matching line wins.
Keep only the source and the package file
Example
Rules: *, !src, !package.json.
src/index.js and package.json are Included. README.md and .env are Excluded by line 1.
Can I re-include a file inside an ignored folder?
Yes. In Docker, a later ! line can bring back a file even when an earlier line excluded its folder, as the docs/README.md example above shows. Git works differently: a file can't be re-included when its parent folder is excluded. So rules copied from .gitignore can give different results here.
Why is my .env.local still in the image?
Because .env matches only a file named exactly .env at the root. .env* also catches .env.local, and **/.env* catches copies in subfolders too, such as config/.env.
Common entries are .git, dependency folders such as node_modules that the image installs again, .env files, build output, and logs. Test each one here before you rely on it.
Does .dockerignore stop the Dockerfile from being sent?
No. You can list Dockerfile and .dockerignore, and the builder still receives them because it needs them. Listing them only stops COPY and ADD from putting them in the image. See Docker's build context guide.
How do I confirm what Docker really sends?
Run a real build and check the COPY step you care about. This tester follows Docker's matching library, moby/patternmatcher v0.6.1. It doesn't look at real files, symlinks, or permissions.
If Docker isn't set up yet, see installing Docker. To check the Compose file that runs the image, use the Docker Compose checker.