Docker
/Beginner
.dockerignore
Definition
A configuration file placed in the build context directory. Before the context is sent to the Docker daemon, any files or directories matching patterns in this file are excluded.
Explain Like I'm New
A VIP list for the kitchen. It tells Docker exactly which garbage files (like massive `node_modules` folders or secret passwords) to ignore when gathering ingredients for the build.
Real World Example
A developer's folder contains a 2GB `node_modules` folder. Without a `.dockerignore`, the `docker build` command takes 5 minutes just to send the context to the daemon. By adding `node_modules/` to the `.dockerignore`, the build starts instantly.
Common Use Cases
- •Optimizing build speed
- •Preventing secret leakage
Interview Questions
basic
- Is `.dockerignore` functionally similar to `.gitignore`?
intermediate
- If you put `secrets.txt` in the `.dockerignore` file, but explicitly write `COPY secrets.txt /app/` in your Dockerfile, what happens?