300-910 · Question #69
Drag and Drop Question. A developer is creating an application where each service uses a different operating system. The application components need to be isolated but must have the ability to communi
This question tests knowledge of Docker multi-stage builds, which allow a single Dockerfile to define multiple build stages using different base OS images while enabling artifact sharing between stages.
Question
Explanation
This question tests knowledge of Docker multi-stage builds, which allow a single Dockerfile to define multiple build stages using different base OS images while enabling artifact sharing between stages.
Approach. A multi-stage Dockerfile uses multiple FROM instructions, each specifying a different base image (e.g., FROM ubuntu:20.04 AS stage1, FROM alpine:3.14 AS stage2). Each stage is isolated with its own OS and filesystem, satisfying the isolation requirement. The COPY --from=<stage_name> instruction allows artifacts (binaries, configs) to be passed between stages, enabling communication of build outputs. The final stage uses EXPOSE to declare network ports, allowing running containers to communicate, and CMD or ENTRYPOINT to define the startup command. The correct order is: FROM (base image/stage definition) → RUN (install dependencies/build) → COPY --from (pull artifacts from prior stages) → EXPOSE (declare ports) → CMD/ENTRYPOINT (launch command).
Concept tested. Docker multi-stage builds - using multiple FROM statements in a single Dockerfile to isolate build environments with different base operating systems, while sharing artifacts across stages via COPY --from and enabling inter-service communication through EXPOSE and Docker networking.
Reference. Docker Documentation: Multi-stage builds - https://docs.docker.com/build/building/multi-stage/
Topics
Community Discussion
No community discussion yet for this question.