A multistage Docker build uses multiple FROM stages to separate compilation from runtime packaging. Named stages let the final image copy only selected artifacts from an earlier stage, excluding compilers and intermediate files. section 12.2.3 section 12.6
Rust release image
Build the release binary with the Rust image, then use a Google Distroless runtime image and copy /app/target/release/docker-rust into it. Build with Dockerfile-lite, run docker-rust-lite on port 8080, and verify the greeting endpoints. The resulting image is reported as 31.8 MB. section 12.2.3
# Use the main rust Docker image FROM rust as build # copy app into Docker image COPY . /app # Set the workdirectory WORKDIR /app # build the app RUN cargo build --release # use google distroless as runtime image FROM gcr.io/distroless/cc-debian11 # copy app from builder COPY --from=build /app/target/release/docker-rust /app/docker-rust WORKDIR /app # start the application CMD ["./docker-rust"]
Shows the complete two-stage Dockerfile, including the builder stage, release compilation, runtime image, artifact copy, and startup command. section 12.2.3

