Shrink an Image with a Multi-Stage Build

medium 20 XP ~7 minHands-on lab

Labs have no container engine, so nothing is built or started: your files are checked by reading them, the way a reviewer or a CI linter would. docker-compose config (to validate Compose files) and hadolint (a Dockerfile linter) are installed.

The image of the Go service in /home/student/projects/label-printer is 900 MB, because it ships the whole Go toolchain and source code to production.

Task

Rewrite the Dockerfile as a multi-stage build:

  • a build stage named build, based on golang:1.23, that compiles a static binary (CGO_ENABLED=0) to /out/label-printer
  • a final stage based on gcr.io/distroless/static-debian12 that contains only the binary, copied from the build stage
  • the final image runs /label-printer as its entrypoint, as a non-root user (distroless provides nonroot, UID 65532)

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

TerminalNot started

Your machine is ready to start

Create a free account to open a machine and get graded.