Bird
Raised Fist0
Dockerdevops~20 mins

Scratch base image for minimal containers in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Scratch Image Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a Scratch-based Dockerfile with a simple file copy
Consider this Dockerfile using the scratch base image:

FROM scratch
COPY hello.txt /hello.txt
CMD ["/hello.txt"]

What will happen when you run this container?
Docker
FROM scratch
COPY hello.txt /hello.txt
CMD ["/hello.txt"]
AThe container will fail to start because /hello.txt is not executable
BThe container will start and print the contents of hello.txt to the console
CThe container will start and run an empty shell
DThe container will fail to build because scratch cannot copy files
Attempts:
2 left
💡 Hint
Scratch images have no shell or runtime environment.
🧠 Conceptual
intermediate
1:30remaining
Why use the scratch base image in Docker?
Which of the following is the main reason to use the scratch base image in Docker containers?
ATo create the smallest possible container image with only your application and its dependencies
BTo automatically include debugging tools in the container
CTo enable running containers with a graphical user interface
DTo have a full Linux environment with all standard utilities
Attempts:
2 left
💡 Hint
Think about container size and minimalism.
❓ Troubleshoot
advanced
2:30remaining
Troubleshooting a failing scratch container with a Go binary
You built a Go application statically linked and created this Dockerfile:

FROM scratch
COPY app /app
CMD ["/app"]

The container fails to start with 'exec format error'. What is the most likely cause?
Docker
FROM scratch
COPY app /app
CMD ["/app"]
AThe CMD syntax is incorrect and should use shell form
BThe Go binary was compiled for a different CPU architecture than the container host
CThe scratch image does not support running Go binaries
DThe app file is missing execute permissions
Attempts:
2 left
💡 Hint
Exec format errors usually relate to binary compatibility.
🔀 Workflow
advanced
2:00remaining
Correct workflow to build a minimal scratch container for a static binary
Which sequence of commands correctly builds and runs a minimal scratch container for a statically compiled binary named 'myapp'?
A1. docker build -t myapp . 2. docker exec myapp /myapp
B1. docker run -it scratch 2. copy myapp inside container 3. run /myapp
C1. docker build -t myapp . 2. docker run -it --rm myapp /bin/sh
D1. docker build -t myapp . 2. docker run myapp
Attempts:
2 left
💡 Hint
Think about building an image and then running it.
✅ Best Practice
expert
3:00remaining
Best practice for adding dependencies to a scratch-based container
You want to create a scratch-based container that runs a Python script. Which approach is best to include Python and your script in the container?
AInstall Python inside the scratch image using apt-get
BDirectly copy the Python script into the scratch image and run it with CMD
CUse a multi-stage build: first stage with a full Python image to install dependencies and copy the Python interpreter and libraries into the scratch image
DUse the scratch image and run the script with 'python script.py' assuming Python is available
Attempts:
2 left
💡 Hint
Scratch images are empty and cannot install packages by themselves.

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

  1. Step 1: Understand what scratch means

    scratch is an empty base image, meaning it has no files or OS inside.
  2. 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.
  3. Final Answer:

    To create a minimal container with only your application and no extra files -> Option C
  4. Quick Check:

    Minimal container = scratch base image [OK]
Hint: Scratch means empty base image for smallest containers [OK]
Common Mistakes:
  • Thinking scratch includes a full OS
  • Assuming scratch installs dependencies automatically
  • Believing scratch provides GUI support
2. Which of the following is the correct way to specify the scratch base image in a Dockerfile?
easy
A. FROM base scratch
B. FROM scratch
C. FROM minimal/scratch
D. FROM scratch:latest

Solution

  1. Step 1: Recall Dockerfile syntax for base images

    The correct syntax is FROM <image-name> without extra words.
  2. Step 2: Check official usage of scratch

    scratch is a special empty image and is referenced simply as FROM scratch.
  3. Final Answer:

    FROM scratch -> Option B
  4. Quick Check:

    Base image syntax = FROM scratch [OK]
Hint: Use exactly 'FROM scratch' in Dockerfile [OK]
Common Mistakes:
  • Adding tags like :latest to scratch
  • Using extra words like 'base' or 'minimal/'
  • Incorrect syntax like FROM scratch:latest
3. Given this Dockerfile snippet using scratch:
FROM scratch
COPY myapp /
CMD ["/myapp"]
What will happen if myapp is not a statically compiled binary?
medium
A. The container will fail to run because dynamic libraries are missing
B. The container will run successfully without errors
C. Docker will automatically add required libraries
D. The container will run but with degraded performance

Solution

  1. Step 1: Understand scratch image limitations

    scratch has no OS or libraries, so dynamic binaries cannot find needed libraries.
  2. Step 2: Analyze what happens with non-static binaries

    Non-statically compiled binaries depend on shared libraries which are missing, causing runtime failure.
  3. Final Answer:

    The container will fail to run because dynamic libraries are missing -> Option A
  4. Quick Check:

    Non-static binary + scratch = runtime failure [OK]
Hint: Scratch needs static binaries; dynamic ones fail [OK]
Common Mistakes:
  • Assuming Docker adds missing libraries automatically
  • Thinking container runs fine without libraries
  • 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

  1. Step 1: Understand "exec format error" meaning

    This error usually means the binary format does not match the CPU architecture.
  2. Step 2: Check other possible causes

    Missing execute permission or dynamic linking cause different errors; syntax errors prevent build.
  3. Final Answer:

    The app binary is not compiled for the container's CPU architecture -> Option D
  4. 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

  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]
Hint: 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard