Docker Series: Episode 23 β€” Docker Swarm Advanced: Services, Secrets & Configs πŸ”



This content originally appeared on DEV Community and was authored by Yash Sonawane

Welcome back to the Docker series! After learning Docker Swarm basics and advanced networking, it’s time to dive deeper into production-ready Swarm setups. In this episode, we’ll cover advanced Swarm services, secrets management, and configuration handling.

🔹 Advanced Services in Swarm

  • Swarm services allow you to manage containers declaratively.
  • You can define:

    • Replicas for scaling
    • Placement constraints (e.g., specific nodes)
    • Update strategies for rolling updates

Example: Service with Constraints

docker service create --name webapp --replicas 3 --constraint 'node.role==worker' nginx
  • This ensures the service only runs on worker nodes.

🔹 Rolling Updates

  • Update services without downtime.
docker service update --image nginx:latest webapp
  • Use flags like --update-parallelism and --update-delay for controlled rollout.

🔹 Docker Secrets

  • Secrets are encrypted and stored in Swarm.
  • Example: Creating and using a secret for a database password
docker secret create db_password ./db_password.txt

Attach to a service:

docker service create --name db --secret db_password postgres:latest
  • Inside the container, the secret is available at /run/secrets/db_password.

🔹 Docker Configs

  • Store configuration files securely in Swarm.
  • Example: Nginx config
docker config create nginx_conf ./nginx.conf

Attach to a service:

docker service create --name web --config source=nginx_conf,target=/etc/nginx/nginx.conf nginx

🔹 Best Practices

  1. Use secrets for sensitive data (passwords, API keys).
  2. Use configs for application configuration files.
  3. Scale services carefully based on node capacity.
  4. Monitor Swarm health and service updates.

🔹 Hands-On Challenge

  1. Create a secret and attach it to a database service.
  2. Create a config file and attach it to a web service.
  3. Deploy the service with placement constraints.
  4. Perform a rolling update to a new image.

✅ Next Episode: Episode 24 β€” Docker Compose + Swarm Integration: Multi-Host Deployments β€” combine Compose simplicity with Swarm orchestration for scalable deployments.


This content originally appeared on DEV Community and was authored by Yash Sonawane