The build context supplies files available to build instructions. Ignore rules reduce transfer and prevent accidental inclusion of unnecessary data.
Before you start
You should understand the difference between an image, a running container and the host. Record where a file, process or network endpoint actually lives before diagnosing a problem. Commands illustrate local experiments; adapt image names and paths to a disposable development environment.
The practical goal is to reason through this situation: Exclude local dependencies, caches and secrets when they are not build inputs. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Inventory build inputs
Identify every file needed by COPY or generated build steps.
Step 2: Exclude irrelevant data
Omit caches, local dependencies and secrets that are not legitimate inputs.
Step 3: Inspect resulting artifacts
A smaller context should still produce a complete reproducible image.
Worked scenario
Exclude local dependencies, caches and secrets when they are not build inputs.
A .dockerignore excludes node_modules and .env but retains the package manifest, lockfile and source. Accidentally excluding a generated artifact required by COPY makes the build incomplete. Ignore rules reduce exposure and transfer; they are not a substitute for keeping secrets out of declared build inputs.
Common mistake
Ignoring a file required by COPY causes a build failure.
Verify the behavior
Build from a clean checkout and check required files plus absence of sensitive local files.
Interview exercise
Choose exclusions deliberately.
Answer and reasoning
Inventory required build inputs and verify the produced image without assuming a smaller context is automatically complete.
Continue learning
Compare the scenario with the Docker interview questions and test your understanding with the Docker MCQs. For terminology and implementation details, consult the reference material.