Skip to the workspace
Pebellslearn by building
Underlying Technologies  ›  Lesson

Shell Commands and Package Managers

Shell Commands 14 minImages are built by running shell commands, so you need everyday commands, simple scripts and the right package manager for the base image.

docker / Shell Commands and Package Managers

Explore each scene at your own pace.

01 · The rule

The rule

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 included

Package 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 curl

apt-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.py

set -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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.