What is .dockerignore and why we need it


Let’s say that your docker build command on a “heavy” project has a lot of delay time.  .dockerignore is what you missed and what you needed.

Docker build context

The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.

You have a 10GB file in the current context. Unless you wanna COPY that file to your docker image, you should ignore it to speed up the build process.

What is .dockerignore file?

The .dockerignore file is very similar to the .gitignore file in that it allows you to specify a list of files or directories that Docker is to ignore during the build process.

.gitignore file ignores files to your project while .dockerignore ignoring files to the docker build’s context.

How to ignore files to the build’s context using .dockerignore

1. Ignore the files that you don’t need



2. Ignore all files but some files that you need (recommended)




0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x