Init swarm
sudo docker swarm init
Start a registry as a service on your swarm
sudo docker service create --name registry --publish published=5000,target=5000 registry:2
# or
sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2
# returns `{}` on successful registry setup
curl http://localhost:5000/v2/
Deploy stack to swarm
sudo docker stack deploy -c docker-compose.yml demo
Check services of stack
sudo docker stack services demo
Should increment counter on successive hits
curl http://localhost:8000
Teardown
sudo docker stack rm demo
sudo docker service rm registry
Bring your Docker Engine out of swarm mode
sudo docker swarm leave --force
- Docker Doc Deploy a stack to a swarm
- Learn more on Docker Service