Welcome to the Satellite Data Masterclass workshop on containerization! This comprehensive guide will walk you through everything you need to know about Docker, Docker Compose, and Kubernetes to build, deploy, and manage containerized applications efficiently.
- Introduction to Containerization
- Docker Basics
- Docker Advanced Usage
- Docker Compose
- Kubernetes Deployment
- Additional Resources
Containerization is a lightweight form of virtualization that packages an application and all its dependencies into a single container image. Containers run consistently across different environments, making development, testing, and deployment more reliable and efficient. Unlike traditional virtual machines, containers share the host OS kernel, allowing them to be more resource-efficient and faster to start.
Key technologies covered in this workshop:
- Docker: The leading container platform to build, ship, and run containers.
- Docker Compose: A tool for defining and running multi-container Docker applications.
- Kubernetes: An orchestration system for automating deployment, scaling, and management of containerized applications.
Docker allows you to package your application and its dependencies into a container image that can run anywhere Docker is installed.
- macOS: Download and install Docker Desktop from https://www.docker.com/products/docker-desktop
- Linux: Follow instructions at https://docs.docker.com/engine/install/
Verify installation by running:
docker --versionCreate a Dockerfile in your project directory:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]Build the image with:
docker build -t hello-docker .Run the container, mapping port 80 inside the container to port 8080 on your host:
docker run -p 8080:8080 hello-docker-d: Run container in detached mode-p: Map ports--name: Assign a name to the container
-
List running containers:
docker ps
-
List all containers (including stopped):
docker ps -a
-
Stop a running container:
docker stop hello-docker
-
Remove a container:
docker rm hello-docker
-
List images:
docker images
-
Remove an image:
docker rmi hello-docker
-
View container logs:
docker logs hello-docker
-
Access a running container’s shell:
docker exec -it hello-docker /bin/bash
-
Tag your image:
docker tag hello-docker your-dockerhub-username/web-advanced:latest
-
Log in to Docker Hub:
docker login
-
Push the image:
docker push your-dockerhub-username/web-advanced:latest
docker run -d -p 8080:80 --name web-advanced \
-e FLASK_ENV=development \
-v $(pwd):/app \
web-advanced-e: Set environment variables-v: Mount host directory into container
Run tests inside the container:
docker exec -it web-advanced pytest tests/Remove all stopped containers:
docker container pruneRemove all unused images:
docker image prune -aRemove all unused volumes:
docker volume pruneRemove all unused networks:
docker network pruneRemove everything (containers, images, volumes, networks):
docker system prune -a --volumesDocker Compose simplifies running multi-container applications by using a single YAML file.
version: '3.8'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/app
environment:
- FLASK_ENV=development
redis:
image: "redis:alpine"-
Start services:
docker-compose up -d
-
View running services:
docker-compose ps
-
Stop services:
docker-compose down
-
View logs:
docker-compose logs -f
-
Rebuild images after changes:
docker-compose build
-
Run one-off commands inside a service container:
docker-compose run web pytest tests/
Kubernetes automates container deployment, scaling, and management.
- Install
kubectlCLI: https://kubernetes.io/docs/tasks/tools/ - Access to a Kubernetes cluster (Minikube, Docker Desktop Kubernetes, or cloud provider)
Verify kubectl installation:
kubectl version --clientCreate a file deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-advanced
spec:
replicas: 3
selector:
matchLabels:
app: web-advanced
template:
metadata:
labels:
app: web-advanced
spec:
containers:
- name: web-advanced
image: your-dockerhub-username/web-advanced:latest
ports:
- containerPort: 80Apply the deployment:
kubectl apply -f deployment.yamlExpose your deployment as a LoadBalancer service:
kubectl expose deployment web-advanced --type=LoadBalancer --port=80Scale to 5 replicas:
kubectl scale deployment web-advanced --replicas=5-
List pods:
kubectl get pods
-
List services:
kubectl get svc
-
Describe a pod:
kubectl describe pod <pod-name>
-
View logs of a pod:
kubectl logs <pod-name>
-
Build and push a new image version with a new tag:
docker build -t your-dockerhub-username/web-advanced:v2 . docker push your-dockerhub-username/web-advanced:v2 -
Update the deployment to use the new image:
kubectl set image deployment/web-advanced web-advanced=your-dockerhub-username/web-advanced:v2 -
Verify rollout status:
kubectl rollout status deployment/web-advanced
Rollback to previous revision:
kubectl rollout undo deployment/web-advancedDelete the service and deployment:
kubectl delete service web-advanced
kubectl delete deployment web-advanced- Docker Documentation: https://docs.docker.com/
- Docker Compose Documentation: https://docs.docker.com/compose/
- Kubernetes Documentation: https://kubernetes.io/docs/
- Satellite Data Resources: https://earthdata.nasa.gov/
Thank you for participating in the Sat Data Masterclass containerization workshop! We hope this guide helps you build, manage, and scale your containerized applications with confidence.