Bird
Raised Fist0
Dockerdevops~20 mins

Distroless images concept in Docker - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Distroless Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use Distroless images in Docker?

Which of the following is the main advantage of using Distroless images for Docker containers?

AThey include a full operating system for easier debugging inside the container
BThey automatically update the container with the latest OS patches
CThey reduce image size and attack surface by excluding package managers and shells
DThey allow running containers without specifying a base image
Attempts:
2 left
💡 Hint

Think about what is removed from Distroless images compared to traditional base images.

💻 Command Output
intermediate
2:00remaining
Output of running a Distroless image without shell

What will happen if you try to run docker run -it distroless/base and then try to execute bash inside the container?

AYou get an error: 'bash: command not found'
BThe container exits immediately because no shell is available
CThe container restarts automatically
DYou get a shell prompt and can run bash commands
Attempts:
2 left
💡 Hint

Distroless images do not include shells like bash.

❓ Configuration
advanced
3:00remaining
Dockerfile using Distroless image for a Go app

Which Dockerfile snippet correctly builds a Go application and uses a Distroless image for the final container?

A
FROM golang:1.20 AS builder
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM gcr.io/distroless/base
COPY --from=builder /app/myapp /
CMD ["/myapp"]
B
FROM golang:1.20
WORKDIR /app
COPY . .
RUN go build -o myapp
FROM ubuntu
COPY --from=builder /app/myapp /
CMD ["/myapp"]
C
FROM alpine
WORKDIR /app
COPY . .
RUN go build -o myapp
CMD ["/myapp"]
D
FROM gcr.io/distroless/base
WORKDIR /app
COPY . .
RUN go build -o myapp
CMD ["/myapp"]
Attempts:
2 left
💡 Hint

Look for a multi-stage build that compiles the app first, then copies the binary into a Distroless image.

❓ Troubleshoot
advanced
2:30remaining
Why does a Distroless container fail to start with 'no such file or directory'?

You built a container using a Distroless image but it fails to start with the error: no such file or directory. What is the most likely cause?

AThe container lacks a shell to run the binary
BThe binary is missing executable permissions
CThe Dockerfile is missing the CMD instruction
DThe binary depends on shared libraries not included in the Distroless image
Attempts:
2 left
💡 Hint

Distroless images include only minimal runtime dependencies.

✅ Best Practice
expert
3:00remaining
Best practice for debugging Distroless containers

Since Distroless containers lack shells and debugging tools, what is the best practice to debug issues inside such containers?

AAdd a shell and debugging tools to the Distroless image
BUse multi-stage builds to create a debug image with tools and run it instead
CRun the container with <code>docker exec -it</code> to get shell access
DRestart the container with verbose logging enabled
Attempts:
2 left
💡 Hint

Think about how to keep the final image minimal but still debug when needed.

Practice

(1/5)
1. What is the main advantage of using distroless images in Docker containers?
easy
A. They keep containers small and secure by including only necessary files
B. They include a full Linux distribution for easier debugging
C. They come with built-in shells and package managers
D. They automatically update the application inside the container

Solution

  1. Step 1: Understand what distroless images contain

    Distroless images include only the application and its runtime dependencies, excluding shells and package managers.
  2. Step 2: Identify the benefit of minimal content

    By including only what is needed, the image size is smaller and the attack surface is reduced, improving security.
  3. Final Answer:

    They keep containers small and secure by including only necessary files -> Option A
  4. Quick Check:

    Minimal content = Small and secure [OK]
Hint: Distroless means minimal, no shells or extras included [OK]
Common Mistakes:
  • Thinking distroless images have shells for debugging
  • Assuming they include full Linux distributions
  • Believing they auto-update applications
2. Which of the following is the correct way to specify a distroless base image in a Dockerfile?
easy
A. FROM ubuntu:latest
B. FROM alpine:3.15
C. FROM gcr.io/distroless/base
D. FROM node:distroless

Solution

  1. Step 1: Identify official distroless image naming

    Distroless images are hosted at gcr.io/distroless with names like 'base', 'static', or language-specific tags.
  2. Step 2: Compare options to distroless naming

    Only 'gcr.io/distroless/base' matches the official distroless image naming convention.
  3. Final Answer:

    FROM gcr.io/distroless/base -> Option C
  4. Quick Check:

    Official distroless images start with gcr.io/distroless [OK]
Hint: Distroless images start with gcr.io/distroless prefix [OK]
Common Mistakes:
  • Using common Linux distros like ubuntu or alpine as distroless
  • Assuming 'node:distroless' is a valid tag
  • Confusing distroless with minimal Linux images
3. Given this Dockerfile snippet using a distroless image:
FROM gcr.io/distroless/base
COPY app /app
CMD ["/app"]

What will happen if you try to run docker run and then execute sh inside the container?
medium
A. You will get a shell prompt because distroless images include shells
B. You will get an error saying 'sh: not found' because no shell is included
C. The container will crash immediately on start
D. The container will open a shell automatically

Solution

  1. Step 1: Understand distroless image contents

    Distroless images do not include shells or package managers, only the app and runtime.
  2. Step 2: Predict shell availability inside container

    Trying to run 'sh' will fail because the shell binary is missing, causing 'sh: not found' error.
  3. Final Answer:

    You will get an error saying 'sh: not found' because no shell is included -> Option B
  4. Quick Check:

    No shell in distroless = 'sh: not found' error [OK]
Hint: Distroless images have no shell, so 'sh' command fails [OK]
Common Mistakes:
  • Assuming shells exist for debugging
  • Expecting container to crash on start
  • Thinking shell opens automatically
4. You wrote this Dockerfile using a distroless image:
FROM gcr.io/distroless/base
COPY app /app
CMD ["/app"]

But when you run the container, it exits immediately with no logs. What is the most likely cause?
medium
A. The CMD syntax is incorrect for distroless images
B. The distroless image requires a shell to run commands
C. The container needs a package manager to start
D. The app binary is missing executable permissions

Solution

  1. Step 1: Check distroless image requirements

    Distroless images run the app binary directly without a shell or package manager.
  2. Step 2: Identify common cause of immediate exit

    If the app binary lacks executable permission, the container will exit immediately without running the app.
  3. Final Answer:

    The app binary is missing executable permissions -> Option D
  4. Quick Check:

    Missing exec permission = container exits immediately [OK]
Hint: Check app permissions; distroless runs binary directly [OK]
Common Mistakes:
  • Thinking distroless needs a shell to run commands
  • Assuming CMD syntax differs for distroless
  • Believing package manager is required to start
5. You want to build a secure production Docker image for a Go app using distroless. Which multi-stage Dockerfile snippet correctly builds and runs the app with minimal image size and attack surface?
hard
A. FROM golang:1.20 AS build WORKDIR /app COPY . . RUN go build -o app FROM gcr.io/distroless/base COPY --from=build /app/app /app CMD ["/app"]
B. FROM golang:1.20 WORKDIR /app COPY . . RUN go build -o app CMD ["./app"]
C. FROM alpine:latest WORKDIR /app COPY . . RUN go build -o app CMD ["./app"]
D. FROM gcr.io/distroless/base COPY app /app RUN go build -o app CMD ["/app"]

Solution

  1. Step 1: Understand multi-stage build for distroless

    Build the Go app in a full image with build tools, then copy the binary into a minimal distroless image.
  2. Step 2: Analyze options for correct multi-stage usage

    Only FROM golang:1.20 AS build WORKDIR /app COPY . . RUN go build -o app FROM gcr.io/distroless/base COPY --from=build /app/app /app CMD ["/app"] uses golang image to build, then copies binary into distroless base image for runtime, minimizing size and attack surface.
  3. Final Answer:

    FROM golang:1.20 AS build WORKDIR /app COPY . . RUN go build -o app FROM gcr.io/distroless/base COPY --from=build /app/app /app CMD ["/app"] -> Option A
  4. Quick Check:

    Build in full image, run in distroless = secure minimal image [OK]
Hint: Build in full image, copy binary to distroless for runtime [OK]
Common Mistakes:
  • Trying to build inside distroless image (no build tools)
  • Using single-stage build with full image (larger size)
  • Using alpine without distroless for production
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