0
0
Dockerdevops~20 mins

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

Choose your learning style9 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.