Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

299
Vistas
How do I check that a docker host is in swarm mode?

After executing this;

eval $(docker-machine env mymachine)

How do I check if the docker daemon on mymachine is a swarm manager?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

To check general swarm membership, my preferred method is to use the formatted output from docker info. The possible values of this are currently inactive, pending, active, locked, and error:

case "$(docker info --format '{{.Swarm.LocalNodeState}}')" in
  inactive)
    echo "Node is not in a swarm cluster";;
  pending)
    echo "Node is not in a swarm cluster";;
  active)
    echo "Node is in a swarm cluster";;
  locked)
    echo "Node is in a locked swarm cluster";;
  error)
    echo "Node is in an error state";;
  *)
    echo "Unknown state $(docker info --format '{{.Swarm.LocalNodeState}}')";;
esac

To check for manager status, rather than just a node in a cluster, the field you want is .Swarm.ControlAvailable:

docker info --format '{{.Swarm.ControlAvailable}}'

That will output "true" for managers, and "false" for any node that is a worker or not in a swarm.

To identify worker nodes, you can join to two:

if [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "active" \
     -a "$(docker info --format '{{.Swarm.ControlAvailable}}')" = "false" ]; then
  echo "node is a worker"
else
  echo "node is not a worker"
fi
about 4 years ago · Santiago Trujillo Denunciar

0

You could also use docker info to see the result of Swarm property (inactive or active).

For example:

function isSwarmNode(){
    if [ "$(docker info | grep Swarm | sed 's/Swarm: //g')" == "inactive" ]; then
        echo false;
    else
        echo true;
    fi
}
about 4 years ago · Santiago Trujillo Denunciar

0

I don't have a swarm node handy at the moment, but it looks as if you could simply run something like docker node ls. When targeting a docker daemon that is not in swarm node, that 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 nonzero exit code

$ echo $?
1

So the test would look something like:

if docker node ls > /dev/null 2>&1; then
  echo this is a swarm node
else
  echo this is a standalone node
fi
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda