The scratch base image is an empty image with no files or operating system. It is used to build minimal containers containing only your application and its dependencies.
Click to reveal answer
beginner
Why use the scratch image for containers?
Using scratch creates very small containers, improving security and performance by including only what is necessary to run the app.
Click to reveal answer
beginner
How do you specify the scratch image in a Dockerfile?
You write FROM scratch at the top of your Dockerfile to start building from an empty base image.
Click to reveal answer
intermediate
What must you include in a container built from scratch to make it runnable?
You must add your application binary and any required files manually because scratch has no OS or tools.
Click to reveal answer
beginner
Give an example of a simple Dockerfile using scratch.
Example:
FROM scratch
COPY myapp /
CMD ["/myapp"]
This copies a binary myapp into the container and runs it.
Click to reveal answer
What does the scratch image contain?
AA minimal Linux OS
BA full Ubuntu system
CNothing, it is empty
DOnly shell utilities
✗ Incorrect
The scratch image is completely empty with no files or OS.
Which Dockerfile line starts a build from the scratch image?
AFROM scratch
BFROM ubuntu
CFROM alpine
DFROM base
✗ Incorrect
You specify FROM scratch to start from an empty image.
Why might you choose scratch over other base images?
ATo create the smallest possible container
BTo get a full OS environment
CTo have pre-installed tools
DTo use a graphical interface
✗ Incorrect
Scratch is used to build minimal containers with only your app.
What must you do when using scratch as base image?
ANothing, it has everything needed
BInstall an OS inside the container
CUse a package manager
DManually add your app and dependencies
✗ Incorrect
Since scratch is empty, you must add your app and any needed files.
Which command runs your app in a scratch-based container?
ARUN /myapp
BCMD ["/myapp"]
CENTRYPOINT /bin/bash
DSTART /myapp
✗ Incorrect
You use CMD with the path to your app binary to run it.
Explain what the scratch base image is and why it is useful.
Think about what is inside the image and what you need to add.
You got /4 concepts.
Describe how to create a Dockerfile using the scratch image to run a simple binary.
Focus on the minimal steps needed in the Dockerfile.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using the scratch base image in Docker?
easy
A. To automatically install dependencies for your app
B. To include a full Linux operating system inside the container
C. To create a minimal container with only your application and no extra files
D. To provide a graphical user interface for the container
Solution
Step 1: Understand what scratch means
scratch is an empty base image, meaning it has no files or OS inside.
Step 2: Identify the purpose of minimal containers
Using scratch lets you build very small containers by including only your app and its static binaries.
Final Answer:
To create a minimal container with only your application and no extra files -> Option C
Quick Check:
Minimal container = scratch base image [OK]
Hint: Scratch means empty base image for smallest containers [OK]
Believing performance is only affected, not failure
4. You wrote this Dockerfile:
FROM scratch
COPY app /
CMD ["/app"]
But when running the container, it fails with "exec format error". What is the most likely cause?
medium
A. The Dockerfile syntax is incorrect
B. The app file is missing execute permissions
C. The app binary is dynamically linked
D. The app binary is not compiled for the container's CPU architecture
Solution
Step 1: Understand "exec format error" meaning
This error usually means the binary format does not match the CPU architecture.
Step 2: Check other possible causes
Missing execute permission or dynamic linking cause different errors; syntax errors prevent build.
Final Answer:
The app binary is not compiled for the container's CPU architecture -> Option D
Quick Check:
Exec format error = wrong CPU architecture binary [OK]
Hint: Exec format error means binary architecture mismatch [OK]
Common Mistakes:
Confusing exec format error with permission issues
Assuming dynamic linking causes exec format error
Thinking Dockerfile syntax causes this runtime error
5. 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
A. Compile the Go app statically, use FROM scratch, copy the binary, and set CMD
B. Use FROM scratch, copy the Go source code, and run go run inside the container
C. Use FROM alpine, install Go, and compile the app inside the container
D. Compile the Go app dynamically, use FROM scratch, copy the binary, and set CMD
Solution
Step 1: Compile Go app statically
Static compilation bundles all dependencies, so the binary runs without extra libraries.
Step 2: Use FROM scratch and copy binary
Since scratch is empty, copy the static binary and set the command to run it.
Final Answer:
Compile the Go app statically, use FROM scratch, copy the binary, and set CMD -> Option A
Quick Check:
Static binary + scratch base = minimal working container [OK]