Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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
over 4 years ago · Santiago Trujillo Relatório

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
}
over 4 years ago · Santiago Trujillo Relatório

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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda