Bird
Raised Fist0
Dockerdevops~10 mins

Choosing small base images (alpine, slim) in Docker - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the Dockerfile to use a small base image for a Python app.

Docker
FROM python:[1]
COPY app.py /app/
CMD ["python", "/app/app.py"]
Drag options to blanks, or click blank then click option'
Alatest
Balpine
Cbuster
Dwindows
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'latest' results in a larger image.
Using 'windows' is not suitable for Linux containers.
2fill in blank
medium

Complete the Dockerfile to use a slim version of Node.js base image.

Docker
FROM node:[1]
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
Drag options to blanks, or click blank then click option'
Abuster
Balpine
Cstretch
Dslim
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alpine' may cause compatibility issues with some Node.js packages.
3fill in blank
hard

Fix the error in the Dockerfile to use Alpine base image for a Go app.

Docker
FROM golang:[1]
WORKDIR /go/src/app
COPY . .
RUN go build -o app
CMD ["./app"]
Drag options to blanks, or click blank then click option'
Awindows
Blatest
Calpine
Dbuster
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'windows' causes incompatibility with Linux commands.
Using 'latest' results in a larger image.
4fill in blank
hard

Fill both blanks to create a Python dictionary comprehension that filters packages by size and uses a small base image.

Docker
packages = {pkg: size for pkg, size in package_sizes.items() if size [1] 50 and pkg.startswith('[2]')}
Drag options to blanks, or click blank then click option'
A<
B>
Calpine
Dslim
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' filters larger packages.
Using 'slim' does not match the package prefix in this example.
5fill in blank
hard

Fill all three blanks to create a Dockerfile snippet that uses a small base image, sets working directory, and runs a command.

Docker
FROM [1]
WORKDIR [2]
CMD ["[3]"]
Drag options to blanks, or click blank then click option'
Apython:alpine
B/app
Cpython
Dnode:slim
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node:slim' with Python commands causes errors.
Not setting a working directory can cause file path issues.

Practice

(1/5)
1. Why do developers often choose small base images like alpine or slim when building Docker containers?
easy
A. To reduce image size and speed up container startup
B. To increase the number of installed packages by default
C. To make the container run only on Windows systems
D. To disable networking inside the container

Solution

  1. Step 1: Understand the purpose of small base images

    Small base images like alpine or slim are designed to be lightweight, which means they have fewer files and smaller size.
  2. Step 2: Connect size to performance

    Smaller images download faster and start containers quicker, improving efficiency.
  3. Final Answer:

    To reduce image size and speed up container startup -> Option A
  4. Quick Check:

    Small base images = smaller size and faster startup [OK]
Hint: Small images mean faster downloads and startups [OK]
Common Mistakes:
  • Thinking small images have more packages by default
  • Assuming small images restrict OS compatibility
  • Believing small images disable networking
2. Which of the following is the correct way to specify the Alpine base image in a Dockerfile?
easy
A. IMAGE alpine:latest
B. FROM alpine/latest
C. BASE alpine:latest
D. FROM alpine:latest

Solution

  1. Step 1: Recall Dockerfile syntax for base images

    The correct keyword to specify a base image is FROM, followed by the image name and tag separated by a colon.
  2. Step 2: Check each option

    FROM alpine:latest uses FROM alpine:latest, which is correct syntax. Options A, B, and C use incorrect keywords or separators.
  3. Final Answer:

    FROM alpine:latest -> Option D
  4. Quick Check:

    Base image syntax = FROM image:tag [OK]
Hint: Use FROM keyword with colon-separated tag [OK]
Common Mistakes:
  • Using slash instead of colon between image and tag
  • Using BASE or IMAGE instead of FROM
  • Omitting the tag separator
3. Given this Dockerfile snippet:
FROM python:3.12-alpine
RUN python --version

What will be the expected output when building this image?
medium
A. Python 3.12.x (Alpine variant)
B. Error: python command not found
C. Python 2.7.x default version
D. No output, build fails silently

Solution

  1. Step 1: Identify the base image and its contents

    The base image is python:3.12-alpine, which includes Python 3.12 installed on Alpine Linux.
  2. Step 2: Understand the RUN command effect

    The command python --version will print the Python version installed in the image during build.
  3. Final Answer:

    Python 3.12.x (Alpine variant) -> Option A
  4. Quick Check:

    python:3.12-alpine includes Python 3.12 [OK]
Hint: Tagged python alpine images include Python by default [OK]
Common Mistakes:
  • Assuming python is missing in alpine variant
  • Confusing Python 2 with Python 3
  • Expecting silent build without output
4. You wrote this Dockerfile:
FROM node:18-slim
RUN apk add curl

But the build fails with "apk: command not found". What is the problem?
medium
A. You must install curl before FROM statement
B. Node 18-slim image does not support RUN commands
C. The slim image uses apt, not apk, so apk command is missing
D. The command should be RUN apt-get add curl

Solution

  1. Step 1: Identify the base image OS

    The node:18-slim image is based on Debian, which uses apt package manager, not apk.
  2. Step 2: Understand the error cause

    Using apk (Alpine package manager) on Debian-based image causes "command not found" error.
  3. Final Answer:

    The slim image uses apt, not apk, so apk command is missing -> Option C
  4. Quick Check:

    Debian slim uses apt, not apk [OK]
Hint: Use apt on slim (Debian), apk on alpine [OK]
Common Mistakes:
  • Trying apk on Debian-based images
  • Placing RUN commands before FROM
  • Using unsupported RUN syntax
5. You want a small Docker image for a Python app but need some common Linux tools like curl and bash. Which base image choice balances size and compatibility best?
hard
A. python:3.12-alpine (smallest but may need extra setup)
B. python:3.12-slim (slightly larger but includes common tools)
C. python:3.12-full (largest, includes all tools by default)
D. python:3.12-minimal (no tools, smallest size)

Solution

  1. Step 1: Compare alpine and slim images

    Alpine is smallest but often lacks common tools, requiring manual installs. Slim is bigger but includes many common Linux utilities.
  2. Step 2: Match needs to image choice

    Since you need tools like curl and bash, slim is a better balance of size and compatibility than alpine.
  3. Final Answer:

    python:3.12-slim (slightly larger but includes common tools) -> Option B
  4. Quick Check:

    Slim balances size and tools better than alpine [OK]
Hint: Choose slim for tools, alpine for smallest size [OK]
Common Mistakes:
  • Picking alpine without adding needed tools
  • Assuming minimal includes tools
  • Choosing full image without size concern
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