Bird
0
0

You want to build a minimal Docker container using scratch that runs a Go application. Which steps should you follow to ensure the container runs correctly?

hard📝 Best Practice Q15 of 15
Docker - Image Optimization
You want to build a minimal Docker container using scratch that runs a Go application. Which steps should you follow to ensure the container runs correctly?
ACompile the Go app statically, use <code>FROM scratch</code>, copy the binary, and set CMD
BUse <code>FROM scratch</code>, copy the Go source code, and run <code>go run</code> inside the container
CUse <code>FROM alpine</code>, install Go, and compile the app inside the container
DCompile the Go app dynamically, use <code>FROM scratch</code>, copy the binary, and set CMD
Step-by-Step Solution
Solution:
  1. Step 1: Compile Go app statically

    Static compilation bundles all dependencies, so the binary runs without extra libraries.
  2. Step 2: Use FROM scratch and copy binary

    Since scratch is empty, copy the static binary and set the command to run it.
  3. Final Answer:

    Compile the Go app statically, use FROM scratch, copy the binary, and set CMD -> Option A
  4. Quick Check:

    Static binary + scratch base = minimal working container [OK]
Quick Trick: Static binary + FROM scratch + copy + CMD = minimal container [OK]
Common Mistakes:
  • Trying to run source code inside scratch
  • Using dynamic binaries with scratch
  • Using alpine base instead of scratch for minimal size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes