In this post will show you how to use the
.dockerignore. It will help reducing Docker image size, speedup docker build and avoid unintended secret exposure.
.dockerignore behaviors same as
.gitignore, it removes the extra unwanted files from your image, so you only end up with the files you need for running your application.
The COPY command in a
.dockerfile will blindly copy everything from a folder, to image. If you add
.dockerignore file to your project. This file will instruct the
COPY command of your
Dockerfile, to ignore certain files and folders.
Here is my
.dockerignore file for one of my node project.
node_modules .dockerignore Dockerfile npm-debug.log .git .hg .svn