Shell Commands and Package Managers
quicknotes needs curl inside its image so a health check can call the app. Nobody clicks an installer inside a container: every tool gets there because a line in a Dockerfile ran a shell command. Before going deeper into Docker, you need the small slice of Linux those lines are written in.
The rule
A Dockerfile is a shell script that leaves a filesystem behind.
Each RUN line in a Dockerfile is handed to a shell (/bin/sh -c on Linux images). Whatever files the command creates or changes are saved into the image. So three skills carry you a long way:
Everyday commands, which you will also type inside running containers:
ls -l /app # list files with owners and permissions
cat requirements.txt # print a file
echo "$PATH" # print a variable
mkdir -p /app/data # create a folder, parents includedPackage managers, which install software. Which one you use depends on the base image's Linux family:
# Debian or Ubuntu base
RUN apt-get update && apt-get install -y curl
# Alpine base
RUN apk add --no-cache curlapt-get update downloads a fresh list of available packages; install -y answers "yes" automatically, because a build has nobody at the keyboard. Alpine's apk add --no-cache fetches the list just for this command and does not store it in the image.
Small scripts, often used as a container's start-up step:
#!/bin/sh
set -e
echo "Starting quicknotes"
exec python app.pyset -e stops the script at the first failing command instead of carrying on in a broken state. exec replaces the shell with the app, so the app receives stop signals directly.
The shortcut
Know the base, know the package manager. Look at the FROM line first: debian, ubuntu or a -slim Python/Node tag means apt-get; alpine means apk; Fedora-style bases use dnf. Then make every command non-interactive.
Read the FROM line
FROM python:3.12-slimis built on Debian, so the tool isapt-get.
The common mistake is putting apt-get update alone on one RUN line and the install on the next. Docker may reuse the old update layer from its cache, and the install then works from an outdated package list.
Drills
Answer fast — trust the rule.
Your Dockerfile starts FROM alpine:3.20. Which command installs curl?
Why does a Dockerfile use apt-get install -y rather than plain apt-get install?
What does set -e do at the top of a shell script?
Why join apt-get update && apt-get install -y curl in one RUN?
Remember
- A Dockerfile is a shell script that leaves a filesystem behind: each
RUNis a shell command whose results are saved. - Know the base, know the package manager: Debian/Ubuntu →
apt-get, Alpine →apk, Fedora →dnf. - Trap: interactive prompts and a separate, cached
apt-get update.
