Skip to content

Container Development with Docker — Free Starter Lesson

Free software starter lesson · 15 minutes · Beginner. Build a Docker image for a tiny Python program, run it as a container, and check which version of the program is in the image. You’ll need a working Docker installation.

1. Create a program and a Dockerfile

In a new folder, save the first example as app.py and the second as Dockerfile, with no filename extension.

print("Hello from Econoria")
FROM python:3.12-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]

2. Build and run the image

From the folder containing both files, run these commands. The first build may download the base image. The container prints one line and exits. The --rm option removes the stopped container after it exits.

docker build -t econoria-hello:v1 .
docker run --rm econoria-hello:v1

Try it yourself

Change the greeting in app.py to Hello from version two. Run econoria-hello:v1 again before rebuilding. Then build with docker build -t econoria-hello:v2 . and run docker run --rm econoria-hello:v2. Compare the two outputs.

Self-check

Version one should still print the original greeting, and version two should print the new one. The build copied the file into each image. Editing the file on your computer only affects a subsequent build.

Watch the Docker Containers video for a companion overview.

Browse the other free starter lessons on Learning Progress.