A build needs a 2 GB dataset only for tests. How do you keep it out of the image?
IntermediateScenarioImage design and Dockerfile decisions
Answer
Situation read → Anything COPYed in any stage of the final image's chain stays in it.
What I'd do →
- Put tests in a separate stage (
FROM build AS test) and run withdocker build --target test. - Mount the data with
RUN --mount=type=bind,source=testdata,target=/testdata .... - Exclude it in
.dockerignorefrom the default context.
Why → Bind and cache mounts exist only during the RUN step and are not committed.
Interview tip → Use --target to produce different artifacts from one Dockerfile.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner