Docker Swarm Cheatsheet - adonisv79/bytecommander.com GitHub Wiki

Make current machine a swarm master

// format: docker swarm init --advertise-addr {ip-address}
docker swarm init --advertise-addr 127.0.0.1

Join a docker swarm (this command will also be printed out by the master once you have initialized as above

//format: docker swarm join --token {swarm-token} {ip-address + port}

Start a container in a swarm

// format: docker service create { --name {app-name} } {--mode {replica mode}} -d { -p 3000:3000} {docker-image-name and/or version}
docker service create --name my-app --mode global -d -p 3000:3000 adonisv7/test-api

List services running in a docker host (master or worker)

docker service ls

List the nodes that run a replica of a particular container

// format: docker service ps {container-id or container-name}
docker service ps my-app