How to know service is running on which node in swarm?

Hello everyone.
How can i decide/know which node my service is running on?
For example, i followed the Docker’s tutorial and deployed the helloworld like this on node-manager
docker service create --replicas 1 --name helloworld alpine ping


The problem was:i didn’t know which node the helloworld is running on. Here’s the output of service helloworld on manager-node
root@ip-10-0-2-232:~# docker service ps helloworld
3sptgbwsvwe7x0qrwclslfkw3 helloworld.1 alpine ip-10-0-2-202 Running Running 27 minutes ago

And here’s the output about ID of all nodes in swarm
5qhpz16bi9fzaoslfag2dp6ci * ip-10-0-2-232 Ready Active Leader
d0w2k6dwgk32a09qsz3xp6evn ip-10-0-2-202 Ready Active

I’m so confused about this. Hope someone shed the light on this.

When you do a “docker service ps {service name}” it should spit out a tabulated list, with the node field being the 4th column. From the sample you posted the node ID is ip-10-0-2-202, which would be the hostname of the Docker host. This is keyed off the hostname of the node, so setting that to the desired value instead of ip-10-0-2-202 would be what you are after.

Thank you so much!
And i have one more question
I followed the tutorial in Docker homepage here

At the step 2. Run the command
$ docker service create --replicas 1 --name helloworld alpine ping


There is a long string 9uk4639qpg7npwf3fn2aasksr. I don’t understand what that means. Can you tell me what is it?

That would be the UID of the service that was created.

How do i find out the UID for every service that i want to run?
Sorry to ask the following question, maybe it’s dump question.
For example, i have swarm which contains 1 node manager and 4 other nodes. I want to deploy Wordpress site on all 5 node from node-manager. Is that possible? Or i have to install wordpress on every node separately and node-manager is just a tool to manager, start/stop node?

The UID is created when the service is and is never the same. When you create the service you tell it how many replicas you want running or you can change this on an existing service through an update command.
The beautiful thing about swarm is you don’t care about where each replica runs as long as the required amount of replicas are running and if a noise goes down then the warm will maintain the replica count on the remaining nodes. Also swarm will provide the VIP functionality to route incoming connections to containers as appropriate.
So with that you may want to look at having multiple manager nodes for HA purposes.

1 Like

Thank you so much :smile: