← Back to Home
⚙️ DevOps & Deployment
Deploy applications using modern DevOps tools
1. Docker - Package Your Application
What is it? Docker packages your application and all its dependencies into a container. Like putting your app in a box that works anywhere.
Dockerfile
# Start from base image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Copy files
COPY requirements.txt .
# Install dependencies
RUN pip install -r requirements.txt
# Copy application
COPY . .
# Expose port
EXPOSE 5000
# Run application
CMD ["python", "app.py"]
2. Docker Commands - Build and Run
What is it? These commands let you build Docker containers and run them on any computer.
docker_commands.sh
# Build an image
docker build -t my_app:1.0 .
# Run a container
docker run -p 8000:5000 my_app:1.0
# List running containers
docker ps
# List all containers
docker ps -a
# Stop a container
docker stop container_id
# View logs
docker logs container_id
# Execute command in container
docker exec -it container_id bash
3. Docker Compose - Multiple Services
What is it? Docker Compose lets you run multiple containers together. Like having your app, database, and web server all working together.
docker-compose.yml
version: '3.8'
services:
web:
build: .
ports:
- "8000:5000"
environment:
- DATABASE_URL=postgres://user:pass@db/dbname
depends_on:
- db
db:
image: postgres:13
environment:
- POSTGRES_PASSWORD=password
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
4. Docker Compose Commands
What is it? Commands to manage your multi-container application with one file.
docker-compose_commands.sh
# Start services in background
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
# Execute command in service
docker-compose exec web bash
# Rebuild containers
docker-compose up --build
5. GitHub Actions - Automatic Deployment
What is it? GitHub Actions automatically builds and deploys your code when you push changes. Like having a robot that deploys for you.
.github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: docker build -t my_app .
- name: Run tests
run: docker run my_app pytest
- name: Deploy
run: echo "Deploying..."
6. Kubernetes - Scale Your Application
What is it? Kubernetes manages many containers across multiple computers. It ensures your app stays running and handles traffic spikes.
kubernetes_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my_app
spec:
replicas: 3 # Run 3 copies
selector:
matchLabels:
app: my_app
template:
metadata:
labels:
app: my_app
spec:
containers:
- name: app
image: my_app:1.0
ports:
- containerPort: 5000
