SuperAPI AI Directory

docker-production

Deployment & operations

View repository

Updated 10-15 21:48

About this skill

Docker Production — Production Environment Deployment

Guidance for deploying and managing Docker in production.

When to Use

ALWAYS use this skill when the user mentions:

  • "Production Deployment", "production Docker"
  • "docker swarm", "docker stack", "swarm cluster"
  • "Kubernetes migration", "kompose", "K8s"
  • "Zero-downtime deployment", "rolling update"
  • "Container monitoring", "monitoring", "Prometheus"

Docker Swarm Quick Start

# Initialize cluster
docker swarm init --advertise-addr <MANAGER-IP>
Join workers (run on worker nodes)

docker swarm join --token :2377

Deploy a stack

docker stack deploy -c docker-compose.yml myapp

Manage services

docker service ls docker service scale myapp_web=5 docker service update --image myapp:v2 myapp_web docker service logs -f myapp_web


### Swarm Compose Example

```yaml
version: '3.8'
services:
  web:
    image: myapp:${TAG:-latest}
    deploy:
      replicas: 3
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      rollback_config:
        parallelism: 1
        delay: 10s
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
    ports:
      - "80:8080"

Zero-Downtime Deployment

Rolling Update Flow:

┌──────┐  ┌──────┐  ┌──────┐     Old replicas (v1)
│ v1  │  │ v1  │  │ v1  │
└──────┘  └──────┘  └──────┘

docker service update --image myapp:v2 web

Step 1: Start v2
┌──────┐  ┌──────┐  ┌──────┐  ┌──────┐
│ v1  │  │ v1  │  │ v1  │  │ v2  │    ← 1 new
└──────┘  └──────┘  └──────┘  └──────┘

Step 2: Replace one v1 with v2
┌──────┐  ┌──────┐  ┌──────┐  ┌──────┐
│ v1  │  │ v1  │  │ v2  │  │ v2  │    ← 2 new
└──────┘  └──────┘  └──────┘  └──────┘

... until all v2

Kubernetes Migration

# Convert compose to K8s
kompose convert -f docker-compose.yml

# Output:
# web-deployment.yaml
# web-service.yaml
# ...

# Apply
kubectl apply -f .
Compose K8s
services Deployments + Services
networks Network Policies
volumes PersistentVolumeClaims
deploy.replicas Deployment.spec.replicas
secrets Secrets

Monitoring Stack

cAdvisor + Prometheus + Grafana

# docker-compose.monitoring.yml
services:
  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    ports: ["8080:8080"]
    volumes:
      - /:/rootfs:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /sys:/sys:ro

  prometheus:
    image: prom/prometheus:latest
    ports: ["9090:9090"]
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

  grafana:
    image: grafana/grafana:latest
    ports: ["3000:3000"]

Workflow — Recommended Deployment Process

Step 1: Single-machine deployment: compose.yml + restart: unless-stopped + systemd supervision Step 2: Swarm cluster: docker swarm init → docker stack deploy -c compose.yml myapp Step 3: Rolling update: docker service update --image myapp:v2 + health check + rollback Step 4: Monitoring integration: Prometheus + cAdvisor + Grafana binding dashboard Step 5: K8s migration: kompose convert → manually add resource limits + health checks → Helm Chart

Gotchas — Common Pitfalls

  • Single Swarm manager: If the only manager goes down, the cluster is unresponsive. → Recovery: Use 3 or 5 managers; docker node promote <worker> to add manager; back up /var/lib/docker/swarm/ regularly.
  • Rolling update health check: Without health checks, updates may deploy broken containers. → Recovery: Define HEALTHCHECK in Dockerfile + service health check; use --update-failure-action rollback.
  • Data without volumes: Production databases MUST use volumes. Container restart = new filesystem without volumes. → Recovery: docker service create --mount type=volume,src=db_data,target=/var/lib/mysql.
  • Direct K8s migration: kompose is a starting point, not production-ready K8s configs. → Recovery: After kompose convert, manually add resource limits, health checks, init containers, and ConfigMap/Secret references.

Boundary — Capability Boundaries (Applicable and Non-Applicable Scenarios)

Category Scenario Description
✅ Can do Single-machine Compose production deployment compose.yml + systemd supervision
✅ Can do Swarm cluster management init/join/stack deploy/rolling update
✅ Can do K8s migration solution kompose + manual adjustment + Helm Chart
✅ Can do Production monitoring setup Prometheus + cAdvisor + Grafana + Loki
⚠️ Requires conditions Multi-datacenter Swarm Requires overlay network + low-latency connection
⚠️ Requires conditions Zero-downtime K8s migration Requires blue-green/canary release strategy
❌ Out of scope Application code deployment CI/CD pipelines for various languages
❌ Out of scope K8s cluster setup Use the official K8s documentation
❌ Out of scope Database high availability DBA professional domain + database-native solutions

When NOT to Use

❌ Skip ✅ Use Instead
Development/debugging docker-run
Single-container apps docker-run + systemd
K8s-native from start Skip Swarm, use K8s directly
Docker basics docker-basics

Security & Stability

  • Rotate Swarm join tokens regularly. Leaked worker tokens allow unauthorized node joining.
  • Use Docker Secrets for all sensitive configuration in production stacks.
  • Enable TLS for Docker daemon in production (tlsverify mode).
  • Implement resource limits on all production services to prevent noisy-neighbor issues.
  • Back up Swarm raft data regularly: /var/lib/docker/swarm/.
  • Monitor node health and set up alerts for node failures.

📚 Official Documentation References

Documentation Address
Docker Swarm https://docs.docker.com/engine/swarm/
Docker Stack https://docs.docker.com/engine/swarm/stack-deploy/
Management guide https://docs.docker.com/admin/
Production environment Compose https://docs.docker.com/compose/production/
Secure deployment https://docs.docker.com/engine/security/
Docker engine https://docs.docker.com/engine/

🧭 Docker Skills Journey

📍 You are here: docker-production — Production Deployment

← Previous: docker-cicd | → Next: docker-troubleshooting

FAQ

Q1: How do I quickly get started with this skill? A: Refer to the Quick Start section above and follow the steps.

Q2: What should I do if I encounter a version incompatibility issue? A: Check dependency versions, use a lock file to pin them, and refer to the Common Pitfalls section.

Q3: How do I use this in a production environment? A: Refer to the Best Practices section, ensure the configuration is correct, and set up monitoring and logging properly.

Q4: How can performance be optimized? A: Refer to the performance optimization documentation and use techniques such as caching and indexing.

Q5: How can I contribute or report issues? A: Submit an Issue or Pull Request in the GitHub repository.

Q6: Is Chinese supported? A: Chinese documentation and Chinese comments are supported; see the Domestic Adaptation section for details.