.dockerignore
What it is
Section titled “What it is”A .dockerignore file tells Docker which files and folders must not be included in the build context.
It is essentially identical in spirit to .gitignore, but for the Docker build daemon instead of Git.
Why it matters
Section titled “Why it matters”Without a .dockerignore, the build context will zip up and send everything in our project directory over to the Docker Engine. That often includes things we really do not want inside an image, such as:
node_modules.githistories- local error logs
- editor config files
- temporary build files
- coverage output
- local
.envfiles with secret keys
That kind of sprawl makes our builds:
- slower
- larger
- noisier
- much less secure
- far less predictable
This step is especially critical for Node development.
We do not want to copy your host machine’s node_modules into the final image. Doing so completely defeats the purpose of building in a clean, isolated environment, and can cause strange architecture mismatch errors.
Sound familiar? The above is why I insist that you remove node_modules from your assignments before submitting them.
We definitely do not want to copy our host machine’s .env file into the final image.
To do so would be to invite disaster.
We will discuss how to handle environment variables in a more secure manner later.
A Standard Example
Section titled “A Standard Example”node_modules.git.envnpm-debug.log.DS_StorecoverageExtra Bits & Bytes
Section titled “Extra Bits & Bytes”Docker Docs: .dockerignore files