.dockerignore Generator
Generate a .dockerignore file to keep Docker images lean. Select presets for your language, framework, CI tools, test files, and secrets to exclude unnecessary files from the build context.
Select at least one preset above to generate your .dockerignore file.
What is a .dockerignore file?
A .dockerignore file tells the Docker daemon which files to exclude from the build context sent to the engine when running docker build. Without one, Docker sends your entire project directory - including node_modules, Git history, test fixtures, and local secrets - every time you build. This wastes time, inflates image layers, and risks leaking credentials. A well-crafted .dockerignore speeds up builds significantly and keeps images lean and secure.
Frequently Asked Questions
What is the Docker build context and why does it matter?
When you run docker build ., Docker compresses and uploads everything in the current directory (the "build context") to the Docker daemon before executing any Dockerfile instruction. A large context means a slow upload every build - even if most files are never copied into the image. Use .dockerignore to exclude anything not needed by COPY or ADD instructions.
Should I exclude my Dockerfile from .dockerignore?
You can - the Dockerfile itself is not needed inside the image. However, some CI tools and multi-stage pipelines reference it explicitly, so it's a personal preference. What you should always exclude are other docker-compose.yml files, override files, and any .env files that contain real credentials.
Does .dockerignore affect COPY instructions?
Yes. Files matched by .dockerignore are never sent to the daemon, so COPY . /app will never copy them regardless of what paths you specify. This is different from .gitignore - there is no "un-ignore" mechanism within COPY. If you need a file in the image, don't exclude it here.
How is .dockerignore syntax different from .gitignore?
.dockerignore uses Go's filepath.Match syntax, which is similar to gitignore but not identical. Negation patterns starting with ! work the same way. One key difference: ** in dockerignore matches any path regardless of depth, making **/__pycache__ effective for deeply nested Python cache directories.
What is the biggest win from a good .dockerignore?
Excluding node_modules/ (often hundreds of MB), .git/ (grows unbounded), and build artefacts can reduce build context from gigabytes to megabytes. Combined with a proper multi-stage Dockerfile, this can cut build times from minutes to seconds. Always exclude .env files - a leaked secret in an image pushed to a registry is a serious security incident.