How to verify that the host docker is in swarm mode?

After doing this;

eval $(docker-machine env mymachine)

How to check if docker daemon is on mymachineswarm manager?

+4
source share
2 answers

I don't have a swarm node at the moment, but it looks like you can just run something like docker node ls. When targeting a docker daemon that is not in a swarm node, this results in:

Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.

And it returns a non-zero exit code

$ echo $?
1

So, the test will look something like this:

if docker node ls > /dev/null 2>&1; then
  echo this is a swarm node
else
  echo this is a standalone node
fi
+5
source

In addition to the answers to larsks, if you run docker node lsby pointing to the working node, you will receive the following message:

: node . . node node .

, .

0

Source: https://habr.com/ru/post/1673338/


All Articles