Claude Docker & DevOps Setup Guide Prompt

You are a senior DevOps engineer with expertise in containerisation, CI/CD pipelines, and cloud deployment.

Category
💻 Coding
Difficulty
Advanced
Models
3
Last Updated
2026-06-28
💻 Coding Advanced docker devops containers ci/cd
Works with
📋 Prompt
You are a senior DevOps engineer with expertise in containerisation, CI/CD pipelines, and cloud deployment.

Application: [application type — web app/API/microservice/data pipeline]
Stack: [language/framework — Python/FastAPI/Node.js/React/etc]
Hosting: [hosting environment — AWS/GCP/Azure/Fly.io/Railway/VPS]
Requirements: [deployment requirements — zero-downtime/auto-scaling/HTTPS/multi-service]

Task: Create a complete Docker setup:

1. DOCKERFILE: Production-optimised multi-stage build
2. DOCKER-COMPOSE: Development + production configurations
3. .dockerignore: What to exclude
4. ENVIRONMENT VARIABLES: What to set + where + how to keep secrets safe
5. CI/CD PIPELINE: GitHub Actions workflow for build → test → deploy
6. HEALTH CHECKS: Container health monitoring setup
7. TROUBLESHOOTING GUIDE: Top 5 Docker issues for this stack + fixes
DOCKER SETUP: Python FastAPI app → Fly.io deployment

# Dockerfile (multi-stage, production-optimised)
```dockerfile
# Stage 1: Dependencies
FROM python:3.12-slim AS builder
WORKDIR /build
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Stage 2: Production image
FROM python:3.12-slim
WORKDIR /app

# Security: non-root user
RUN useradd --create-home appuser
USER appuser

# Copy installed packages from builder
COPY --from=builder /root/.local /home/appuser/.local
COPY . .

# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s \
CMD python -c "import requests; requests.get('http://localhost:8000/health')"

EXPOSE 8000
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
```

# docker-compose.yml (development)
```yaml
version: '3.9'
services:
api:
build: .
ports: ["8000:8000"]
volumes: [".:/app"] # hot-reload in dev
environment:
- DEBUG=true
- DATABASE_URL=${DATABASE_URL}
env_file: [.env]

db:
image: postgres:16-alpine
environment:
POSTGRES_DB: appdb
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes: [postgres_data:/var/lib/postgresql/data]

volumes:
postgres_data:
```

# GitHub Actions CI/CD
```yaml
name: Deploy to Fly.io
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
```
🏆
Best model for this prompt
DeepSeek
DeepSeek V3 / R1
💡 Pro Tips
Multi-stage builds are mandatory for production — development dependencies (pytest, black, mypy) should never be in your production image
Use specific version tags (python:3.12-slim, not python:latest) — 'latest' changes without warning and breaks your builds
Never put secrets in Dockerfiles or docker-compose.yml — use environment variables and a secrets manager
Run containers as non-root users — it's a security best practice that's easy to implement and required by some hosting platforms
⚠️ Common Mistakes
COPY . . before installing dependencies — this invalidates cache every time you change any file
Not using .dockerignore — copies node_modules or .venv into the image, making it huge
Hard-coding DATABASE_URL or API keys in config files — use environment variables always
No health check — container orchestrators need health checks to know when to restart failed containers
❓ FAQ 🔗 Related Prompts