What is the difference between Docker Swarm services and Docker Compose services?
Answer
Despite sharing similar YAML syntax, Docker Swarm services and Docker Compose services are different concepts operating at different scales. Docker Compose services: define containers running on a single host; used for local development and single-machine deployments; managed by the Compose CLI (docker compose); containers are not replicated across hosts; restart is local only; depends_on controls startup order; typically no placement constraints. Docker Swarm services: define tasks distributed across a multi-node cluster; multiple replicas run across multiple machines; the Swarm manager schedules and balances; provide built-in load balancing (Swarm's routing mesh distributes requests across replicas on any node); rolling updates with configurable parallelism and delay; placement constraints (node.role == worker, node.labels.environment == production); resource reservations and limits for scheduling; global mode (one replica per node) or replicated mode. Swarm uses the same Compose YAML syntax but with additional fields under deploy:: deploy: replicas: 3 update_config: parallelism: 1 delay: 10s rollback_config: ... placement: constraints: [node.role == worker] resources: limits: cpus: "0.5" memory: 512M. Deploy a stack to Swarm: docker stack deploy -c docker-compose.yml mystack.
Previous
What is Docker networking at a deep level (iptables, veth pairs)?
Next
What is the OCI (Open Container Initiative) and why does it matter?
More Docker Questions
View all →- Advanced What is containerd and how does it relate to Docker?
- Advanced What are Linux namespaces and cgroups, and how do they enable containers?
- Advanced What is overlay2 storage driver and how does it work?
- Advanced What is Docker Buildx and multi-platform builds?
- Advanced What is Docker networking at a deep level (iptables, veth pairs)?