DEV Community

Discussion on: Improve your Dockerfile, best practices

Collapse
 
raqbit profile image
Ramon

The main reason to use a .dockerignore file is because the docker command has to send your complete build-context to the docker daemon, which will then build the image.

If your context is the root of the repo for instance, it will send your whole project to the daemon before evaluating the COPY and ADD commands. This can become expensive when you have a lot of dependencies or store build artifacts in your project.

.dockerignore stops the docker CLI from sending specified files and directories to the daemon.