- Intermediate
- Building images
How it works
It uses patterns like .gitignore: node_modules, .git, *.log, .env. A line starting with ! brings a file back. Ignored files are invisible to COPY and ADD, so COPY . . can no longer pick them up by accident.
What breaks
It must sit at the root of the context: a .dockerignore next to a Dockerfile in another folder is ignored. And ignoring a file that the Dockerfile copies by name, like package-lock.json, makes the build fail with "not found".
In .dockerignore
node_modules
.git
*.log
.env
.env.*
!.env.example
See it break, then fix it
Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.