0
0
Dockerdevops~10 mins

Reducing final image size by 80 percent in Docker - Interactive Code Practice

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

Complete the Dockerfile line to use a smaller base image.

Docker
FROM [1]
Drag options to blanks, or click blank then click option'
Aalpine:latest
Bubuntu:latest
Cdebian:latest
Dcentos:latest
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a full Linux distribution like Ubuntu increases image size.
Using CentOS or Debian also results in larger images.
2fill in blank
medium

Complete the command to remove unnecessary package cache after installation.

Docker
RUN apk add --no-cache curl && rm -rf [1]
Drag options to blanks, or click blank then click option'
A/tmp
B/usr/local/bin
C/var/cache/apk/*
D/etc/apk
Attempts:
3 left
💡 Hint
Common Mistakes
Removing /usr/local/bin deletes installed binaries.
Removing /etc/apk breaks package management.
Removing /tmp may not affect package cache.
3fill in blank
hard

Fix the error in the Dockerfile line to reduce layers by combining commands.

Docker
RUN apk add curl \
    && [1] /var/cache/apk/*
Drag options to blanks, or click blank then click option'
Acp -r
Bmkdir
Ctouch
Drm -rf
Attempts:
3 left
💡 Hint
Common Mistakes
Using mkdir or cp does not remove files.
touch only creates empty files.
4fill in blank
hard

Fill both blanks to create a multi-stage Dockerfile that copies only the final binary.

Docker
FROM golang:1.20-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o [1] .

FROM alpine:latest
COPY --from=builder /app/[2] /usr/local/bin/
CMD ["[3]"]
Drag options to blanks, or click blank then click option'
Aapp
Bmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the binary causes copy errors.
CMD not matching the binary name causes runtime errors.
5fill in blank
hard

Fill all three blanks to create a Dockerfile that cleans up build tools and reduces image size.

Docker
FROM node:18-alpine AS build
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build

FROM alpine:latest
RUN apk add --no-cache [1]
COPY --from=build /app/dist /app
CMD ["[2]", "[3]"]
Drag options to blanks, or click blank then click option'
Anodejs
Bnpm
Cnode
Dserve
Eindex.js
Attempts:
3 left
💡 Hint
Common Mistakes
Installing npm in the final image increases size unnecessarily.
CMD not matching the app entry point causes failure.