I\'m not able to find many examples of what a .dockerignore file should look like.
Using puppet to install a few packages on a docker container causes the image to
Optimizing container image size is the main goal behind the .dockerignore as it serve a purpose similar to your .gitignore as it reduces the latency and response time while providing services. It is true for deployment automation such as Puppet, SaltStack or Ansible. Timestamp defined for service execution deployment may be failed because of larger image size and low network bandwidth. So .dockerignore helps to make the size of image as small as possible.
You could place it into the build context directory which we specify at the end of a docker build command. The file follows glob pattern for files and directories to exclude those from the final build image.
Suppose I have a directory .img/ into my build context, and I want to exclude it while building image, I'll simply add the following line into .dockerignore file,
.img
And, if I want to exclude all files starts with . then simply, add the line,
.*
(Note: Don't confuse the Unix glob pattern is different than Regular expressions)
In addition, I'll exclude few more of my files from my build context,
.*
docs
my-stack.dab
docker-compose.overrride.yml
test*
*.md
!README.md
Here, *.md line excludes all markdown files(I have many markdown files into my project). But, I want to include README.md and no other markdown files. As our last line in above, we have added README.md with ! or exclude it while excluding all other markdown files.
So, with this we can reduce the overhead of your build image with the help of .dockerignore and leverage to make image size smaller.