Free preview
10 minInstalling Docker & First Container
Install Docker and run your first container from the command line.
Docker Concepts: Images & Containers
Before running anything, understand two key terms:
Image — a read-only blueprint (like a class in OOP). Built once, shared everywhere. Container — a running instance of an image (like an object/instance). You can run many containers from one image.Image (blueprint) → Container (running instance)
Python 3.11 → Your running FastAPI app
nginx:latest → Your web server
postgres:15 → Your databaseImages live on Docker Hub (like npm/PyPI but for container images). You pull them and run containers from them.
Your First Docker Commands
# Pull an image from Docker Hub
docker pull python:3.11-slim
# Run a container interactively
docker run -it python:3.11-slim python
>>> print("Hello from inside a container!")
>>> exit()
# Run a command in a container and exit
docker run python:3.11-slim python -c "import sys; print(sys.version)"
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# List downloaded images
docker images
# Remove a stopped container
docker rm <container_id>
# Remove an image
docker rmi python:3.11-slimThe format image:tag specifies the version. python:3.11-slim means Python 3.11, slim variant (smaller image without extra tools).
Multiple choice
What is the relationship between a Docker image and a container?
- AAn image is the blueprint; a container is a running instance of that image
- BA container is the blueprint; an image is a running instance
- CThey are the same thing with different names
- DAn image is a container that has been stopped
Fill in the blank
The command to list all running containers is docker ___.
Multiple choice
What does the :slim tag mean in python:3.11-slim?
- AA smaller image variant without extra development tools
- BA faster but less stable build
- CA beta/preview release
- DA compressed archive