Containers: Docker, Podman#
Docker and Podman are containerization tools that package your application and its dependencies into a standardized unit for software development and deployment.
Docker is the industry standard. Podman is compatible with Docker and has better security (and a slightly more open license). In this course, we recommend Podman but Docker works in the same way.
Initialize the container engine:
podman machine init
podman machine startCommon Operations. (You can use docker instead of podman in the same way.)
# Pull an image
podman pull python:3.11-slim
# Run a container
podman run -it python:3.11-slim
# List containers
podman ps -a
# Stop container
podman stop container_id
# Scan image for vulnerabilities
podman scan myapp:latest
# Remove container
podman rm container_id
# Remove all stopped containers
podman container pruneYou can create a Dockerfile to build a container image. Here’s a sample Dockerfile that converts a Python script into a container image.
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Typically, you would use `COPY . .` to copy files from the host machine,
# but here we're just using a simple script.
RUN echo 'print("Hello, world!")' > app.py
# Run the script
CMD ["python", "app.py"]To build, run, and deploy the container, run these commands:
# Create an account on https://hub.docker.com/ and then login
podman login docker.io
# Build and run the container
podman build -t py-hello .
podman run -it py-hello
# Push the container to Docker Hub. Replace $DOCKER_HUB_USERNAME with your Docker Hub username.
podman push py-hello:latest docker.io/$DOCKER_HUB_USERNAME/py-hello
# Push adding a specific tag, e.g. dev
TAG=dev podman push py-hello docker.io/$DOCKER_HUB_USERNAME/py-hello:$TAGTools:
- Optional: For Windows, see WSL 2 with Docker getting started

