Interview Prep/Docker/Image design and Dockerfile decisions

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 →

  1. Put tests in a separate stage (FROM build AS test) and run with docker build --target test.
  2. Mount the data with RUN --mount=type=bind,source=testdata,target=/testdata ....
  3. Exclude it in .dockerignore from 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.

All Docker questions Roadmap: Docker & containers

More on Image design and Dockerfile decisions