Build in one stage with the full toolchain, then copy only the finished artifact into a small runtime image. Typical result: images 5-10x smaller with no compilers or source code inside.
Start a build stage with the full SDK: FROM <sdk-image> AS build
Build a single stage for testing with docker build --target build -t myapp:build .. Stages that the final stage does not depend on are skipped automatically by BuildKit.