Skip to main content
InterviewHubPRO
Section Overview
Q11

Question 11 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

22%
Docker & Containers (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is the `.dockerignore` file and why is it critical for build speed and security?

junior LevelMost AskedCode ExampleSecurity & AuthDocker & Containers

In Simple Words: When you run docker build ., the Docker CLI transfers everything in the current directory (the Build Context) across the Docker socket to the build daemon. A .dockerignore file excludes unnecessary files from this transfer:

  • Speeds up builds: Avoids sending hundreds of megabytes of node_modules, .git, or build caches over the socket.
  • Prevents cache invalidation: Prevents changes in local files (like .git/logs or README.md) from busting Docker layer cache.
  • Prevents credential leaks: Ensures .env, private SSH keys, and local credentials are never accidentally copied into the final image.
text
# Typical .dockerignore
node_modules
npm-debug.log
.git
.gitignore
.env
.env.local
coverage
dist