"Appendix: Set up a container"
This is an optional appendix. The course does not require a container. This page is here if you want to set one up for the course anyway. If you have not read Why we use containers yet, start there.
This page installs Podman and starts a container for the course. You will type
commands in your real terminal, so if pwd and cd are new, read
Find your way around the terminal first.
Why Podman
Podman is one of several programs that runs containers. We use it here because it is free, open source and works on Mac, Windows and Linux. If you already know Docker, Podman reads the same commands and does the same job.
Recall
What does Podman do?
Show the answer
It runs the course machine, a virtual computer inside yours that has every tool the course needs and is the same for everyone.
Install Podman
- Go to podman-desktop.io and download Podman
Desktop for your system. Run the installer and accept the defaults.
- On Windows, the installer may offer to turn on WSL 2. This is a built-in Windows feature that lets it run Linux programs, which Podman needs. Say yes and restart if it asks.
- Open Podman Desktop. On first launch it offers to install and start Podman. Accept, and wait until its status shows as running.
Check that Podman works
Type this command exactly, then press Enter:
podman run --rm hello-world
Podman downloads a tiny test program, runs it, and prints a message. You should see a line that starts with "Hello from Podman" or "Hello from Docker". That means everything is working. If you see an error instead, check that Podman Desktop is open and shows Podman as running, then try again.
Start the course machine
The course machine expects your work in ~/Projects/python-projects. If you
have not made that folder yet, do so now:
mkdir -p ~/Projects/python-projects
Move into the folder:
cd ~/Projects/python-projects
Start the machine. On Mac, run:
podman run -it --rm -v "$PWD":/home/student/python-projects ghcr.io/branhoff/python-class-env
On Windows (PowerShell), run:
podman run -it --rm -v "${PWD}:/home/student/python-projects" ghcr.io/branhoff/python-class-env
The first run downloads the machine, so it takes a minute. Later runs start at once.
Here is what the command says, piece by piece:
| Part | Meaning |
|---|---|
podman run |
Start a container |
-it |
Let me type into it |
--rm |
Throw it away when I leave |
-v ...:/home/student/python-projects |
Share my current folder with the machine |
ghcr.io/branhoff/python-class-env |
Which machine to start: the course one |
How the shared folder works
The course machine is a virtual computer running inside yours, so it cannot see
your files unless you let it. The -v part of the command does that. The v
stands for volume, Podman's word for a folder shared with a container.
It is one folder with two doors, not a copy. Your computer reaches it at
~/Projects/python-projects. The machine reaches the same folder at
~/python-projects. A file saved on either side is there on the other at
once, so there is nothing to copy or keep in sync.
Only that folder is shared. Anything you save elsewhere inside the machine is
gone when you leave it, so keep your work in python-projects.
You are inside
The prompt changes. It now belongs to the course machine, not your own computer:
~/python-projects %
You now have two terminals. Your own is for starting the machine. Run Python
and every other course command in the machine's terminal, which is
identical for everyone. The prompt shows which one you are in:
~/python-projects % means you are inside the machine.
For every project: write code in VS Code, then run it in the machine.
To leave, type exit and press Enter. You are back in your own terminal. To
come back, cd to your folder and run the same podman run command again.
The nano editor
The course machine also includes a small editor called nano that works inside the terminal. It is handy on a server where there is no VS Code:
nano hello.py
Type your code. The commands for each key are listed along the bottom of the
screen, where ^ means the Ctrl key. Press Ctrl+O then Enter to save, and
Ctrl+X to close.