CS FundamentalsHardProduct-company DevOps interview

A Go service's Docker image is 900 MB because it includes the compiler and build tools. Which change gives a small image containing only the binary?

  1. A. Run apt-get clean at the end of the Dockerfile
  2. B. A multi-stage build: compile in a builder stage, then COPY --from=builder only the binary into a minimal runtime image
  3. C. Use docker commit after deleting the tools in a running container
  4. D. Add the tools folder to .dockerignore

Correct answer: B. A multi-stage build: compile in a builder stage, then COPY --from=builder only the binary into a minimal runtime image

Each instruction adds a layer, so deleting files later does not shrink earlier layers. Multi-stage builds keep the toolchain in a throwaway stage and ship just the artefact, which also reduces the attack surface.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic