About .dockerignore generator
A .dockerignore file keeps unneeded files out of the build context, which makes builds faster and images smaller and safer.
Usually ignored
- .git, node_modules and build output.
- Local .env files and keys.
- Logs, tests and documentation not needed at run time.
A worked example
For a Node.js project the file lists node_modules, .git, .env, npm-debug.log, Dockerfile and docker-compose.yml. Without it, the whole folder, including a large node_modules, is sent to the Docker daemon on every build, which slows it and risks copying secrets into the image.
Tips
- Ignore build output you do not need in the image.
- Never rely on it alone to protect secrets. Use build secrets or environment variables at run time.
- Check the built image with docker history if it is larger than expected.
Smaller, faster builds
A good .dockerignore can shrink the build context from hundreds of megabytes to a few, which speeds up every docker build and every upload to a remote builder.
