🛠 .dockerignore: ignored when building image
Salute,
We looked at the principle of ignoring for .gitignore here, and now we’ll look at the principle for .dockerignore. That is, we will look at what allows you to ignore docker when building an image.
Ignoring is similar to .gitignore:
- Reduces size
- Speeds up assembly
- Increases security with the right restrictions and the use of analogues in the type of storage of artifacts in packages
In .dockerignore these are the rules that support paths, patterns, exception inversions:
- Paths and files: some_docs/
- Templates: *.log
- Ignoring: `!config/default.json
dockerignore:
node_modules
build/
*.log // ignore all logs
.env
!.env.example // leave a specific artifact
How to collect:
docker build -t with_ignore -f Dockerfile .
docker run --rm with_ignore
Total: the outputs are similar to .gitignore, but wider, since the build already goes further than the git repo. There are online services to generate this file, like this dockerignore-generator. Autogenerators allow you to generally assemble a file template. By the way, helmignore is used in the same way for helm charts.
#toolchain #reco
