I recently learned there is a .dockerignore file. The .dockerignore file allows you to exclude files from sending them to the docker deamon like a .gitignore file allows you to exclude files from your git repository.
Okay, and why should I not want to send them to the docker deamon? Who is this docker deamon dude? Docker is some kind of client-server application. Next to the docker client we are running, there is a docker server aka the docker deamon. When I am using docker the command line I am opearting in the docker client. When I build a docker image the files in the build context all are packed inside a tar file and transfered to the docker deamon. Obviously it’s not a bad thing to reduce the size of this file by excluding big not needed files and to avoid putting unnecessary files inside the docker container.
How does it work?
As I said, when you build a docker image, it sends the files to the docker server. Before sending, the docker client checks for a .dockerignore
file. It will modify the build context to exclude the mentioned files & directories.