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.