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
source
share