Docker .gitignore template
The Docker template ignores compose files other than the base and override, along with the .dockerignore file and logs, and both of those choices deserve review.
At a glance
- Category
- Infrastructure
- Patterns in this template
- 5 rules
- Directories ignored
- None. Every rule matches by filename or extension rather than by directory.
- Re-include rules
- 2 lines start with ! to keep something back
- Also needs an OS template
- Yes. This covers a handful of container files and nothing else.
- Typical companions
- The language template for whatever runs inside the image.
In detail
The first three rules work together. docker-compose*.yml ignores every compose file, then two negations bring back docker-compose.yml and docker-compose.override.yml. The intent is that the base file is shared, the override file is where local adjustments go, and any other variant is somebody's personal experiment.
That intent does not match how most projects use compose today. Environment specific files such as docker-compose.prod.yml or docker-compose.ci.yml are usually deliberate, tracked, and referenced from a deploy script. Under this template they are silently ignored, and the failure appears when a colleague clones and the deploy command cannot find the file it expects.
The naming convention has also moved. The current tooling looks for compose.yaml by default, and neither the ignore rule nor its negations mention that name, so a project using it is unaffected by all three rules in either direction. If you have renamed your files to the newer convention, the whole block is doing nothing, and you should replace it with rules that match what you actually have.
.dockerignore is the rule that surprises people most. That file controls what gets sent to the daemon as build context, and excluding a large directory from it is often the difference between a fast build and one that uploads a gigabyte of dependencies. It is project configuration in the same sense a Dockerfile is, and almost every project should track it.
*.log is the last rule and the least controversial, covering container and application logs that end up in the working directory during local runs. What the template does not cover is a .env file, which compose reads by default for variable substitution and which routinely holds database passwords.
Examples
docker-compose*.yml
!docker-compose.yml
!docker-compose.override.yml
.dockerignore
*.log5 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- Ignoring .dockerignore is almost always wrong. That file is build configuration, and losing it means a much larger build context for everyone who clones.
- Environment specific compose files such as docker-compose.prod.yml are caught by the wildcard. Add a negation for any variant your project deliberately tracks.
- Compose reads .env for variable substitution and this template does not ignore it. Add that rule yourself if you keep credentials there.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Terraform .gitignore template
State files contain secrets in plain text and must never be committed. This template covers that, and also ignores the lock file, which should be tracked.
Node.js .gitignore template
The longest JavaScript oriented template: dependency directories, every package manager's debug log, bundler caches, env files and Yarn Plug'n'Play state.
Go .gitignore template
The Go template ignores platform binaries by extension, which misses the extensionless binary go build produces on Linux and macOS. Here is what to add.
Vagrant .gitignore template
Two rules worth understanding: the .vagrant directory holds machine identifiers and a generated private key, and box files are multi gigabyte disk images.
JavaScript .gitignore template
Every rule in the JavaScript .gitignore template explained: why node_modules is restored rather than committed, and what the old package folders catch.
TypeScript .gitignore template
The TypeScript template ignores compiled output, source maps and build info, but its *.d.ts rule is broader than most projects want. Here is each line.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- Dockerfile Generator Generate production-ready Dockerfiles for 18 stacks - multi-stage builds, best practices included
- .env Editor & Validator Edit and validate .env files online - detect duplicates, mask secrets, generate .env.example