A very productive Codenight where we learned about Docker and Docker Compose.

We introduced Docker, Docker Composes, and how they work.

Docker is a containerization platform that packages an application and its dependencies into isolated containers; a Dockerfile defines the step-by-step instructions for building the container image (base image, dependencies, commands, configuration).

# Dockerfile Example
 
# Use Python as the base image
FROM python:3.12
 
# Set working directory inside container
WORKDIR /app
 
# Copy app files into container
COPY . .
 
# Install dependencies
RUN pip install -r requirements.txt
 
# Run the application when container starts
CMD ["python", "main.py"]

Docker Compose is a tool for defining and managing multi-container Docker applications; the docker-compose.yml file describes the services, networks, volumes, and configuration needed to run them together with a single command.

# docker-compose.yml example
 
services:
  web:
    build: .                 # Build image using local Dockerfile
    ports:
      - "8000:8000"          # Host:Container port mapping
    volumes:
      - .:/app               # Bind mount local files into container
    depends_on:
      - db
    networks:
      - app-network          # Connect to custom network
 
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: example
    volumes:
      - db-data:/var/lib/postgresql/data   # Persistent database storage
    networks:
      - app-network
 
networks:
  app-network:       # Custom bridge network for service communication
    driver: bridge
 
volumes:
  db-data:                   # Named volume to persist PostgreSQL data

Another good ~8 hour coding session, where some of you continued with FastAPI, some advanced to custom API Gateways and some fully dockerized their projects.

Plans for next week? Check the [weekly TL;DR](https://blog.librecourse. uy/tldr/v 0.3/).