Loading

Quipoin Menu

Learn • Practice • Grow

docker / Docker .dockerignore
tutorial

Docker .dockerignore

When you build a Docker image, the entire build context (the folder you specify with docker build .) is sent to the Docker daemon. Often, this includes files you don’t need in the image, like temporary files, logs, or local dependencies. The .dockerignore file helps you exclude them, making builds faster and images smaller.

What Is .dockerignore?

It's a text file (similar to .gitignore) that lists patterns of files and folders Docker should ignore when building an image. It sits in the same directory as your Dockerfile.

Using .dockerignore reduces image size, improves build speed, and avoids accidentally including secrets.

Common Patterns

Create a .dockerignore file in the build context folder and add patterns like:
# Node.js
node_modules/
npm-debug.log

# Python
__pycache__/
*.pyc
*.pyo

# General
.git/
.env
.DS_Store
*.log
tmp/

Example: Node.js Application

If your app has a node_modules folder locally, you should ignore it because the image will reinstall dependencies via RUN npm install. Your .dockerignore might look like:
node_modules/
.env
.git
Dockerfile
.dockerignore

Best Practices

  • Always include a .dockerignore in your project.
  • Exclude version control folders (.git).
  • Exclude local environment files (e.g., .env).
  • Exclude development dependencies that you don't need in production.
  • Test by building and checking image size with docker images.


Two Minute Drill
  • .dockerignore excludes files from the build context.
  • It speeds up builds and reduces image size.
  • Use patterns like node_modules/, *.log, .git/.
  • Place it in the same folder as your Dockerfile.

Need more clarification?

Drop us an email at career@quipoinfotech.com