Data in Motion 2: Containers
This workshop introduces containerization concepts using Docker, progressing from single-container applications to multi-container orchestrated systems.
- Location:
part1/ - Files:
Dockerfile: Container definition for a Python applicationmessage.py: Python script that prints a joke
- Objective: Learn basic Docker concepts by containerizing a simple Python script
- Location:
part2/ - Files:
docker-compose.yaml: Orchestration configuration for the entire stackingest/: Data ingestion serviceapp.py: Fetches ISS position data from API and stores in PostgreSQLDockerfile: Container definitionrequirements.txt: Python dependencies (requests, psycopg2-binary)
transform-worker/: Data transformation serviceapp.py: Calculates latitude/longitude changes between consecutive ISS positionsDockerfile: Container definitionrequirements.txt: Python dependencies (requests, psycopg2-binary)
- Objective: Build a complete data pipeline using Docker Compose with PostgreSQL, ingestion, and transformation services
- Docker Desktop installed and running
- Basic understanding of Python
- Familiarity with command line operations
-
Navigate to the part1 directory:
cd part1 -
Complete the
message.pyscript to print a joke -
Complete the
Dockerfilewith appropriate instructions:- Base image (Python runtime)
- Working directory
- Copy the Python script
- Command to run the script
-
Build and run the container:
docker build -t joke-app . docker run joke-app
-
Navigate to the part2 directory:
cd part2 -
Start the entire stack:
docker-compose up --build
-
The pipeline will:
- Start a PostgreSQL database
- Launch the ingest service to fetch ISS position data every 5 seconds
- Launch the transform-worker to calculate position changes every 30 seconds
-
Monitor the logs to see data being processed
-
To stop the services:
docker-compose down
- Understand containerization fundamentals
- Create Dockerfiles for Python applications
- Use Docker Compose for multi-service applications
- Implement data ingestion and transformation patterns
- Work with containerized databases
- Handle inter-service dependencies
- Ingest Service: Polls the Open Notify ISS API every 5 seconds
- Database: Stores raw position data in PostgreSQL
- Transform Worker: Processes unprocessed records, calculating lat/long changes from previous positions
- Database: Updates records with calculated changes
- Ensure Docker Desktop is running
- Check container logs with
docker-compose logs <service-name> - Verify port 5432 is available (PostgreSQL)
- Use
docker-compose psto check service status