Docker swarm commands

Start a swarm in the manager node:

docker swarm init --advertise-addr 

To join swarm cluster as worker or manager

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

If you forget above command, run following command to regenerate it from the swarm manager:

docker swarm join-token worke

To check current state of the swarm, run from manager and worker

 docker info

To see the swarm nodes

docker node ls

Start a service

To start a service:

docker service create --replicas 5 -p 80:80 --name web nginx

status of the service

docker service ls
docker service inspect --pretty helloworld

to see which nodes are running the service:

docker service ps helloworld

Scale the service in the swarm

docker service scale helloworld=5

To delete the service

$ docker service rm helloworld

Manage nodes

To view a list of nodes in the swarm run docker node ls from a manager node:

 docker node ls

Inspect node

docker node inspect self --pretty

Update a node

You can modify node attributes as follows:

Give a node a label:

docker node update –label-add ostype=pi raspberrypi

I gave my raspberry pi a lable ‘ostype=pi’


docker service create –name gatewayarm –constraint ‘node.labels.ostype == pi’ openmtc/gateway-arm

So, the service will start container only on node labeled as ‘pi’.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s