Terraform cannot force docker to join swarm

I am trying to use Terraform to deploy some EC2 server that I am setting up to run Docker. I got all the code for this github repo .

Mistake

aws_instance.swarm-node.0 (remote-exec): Connected!
aws_instance.swarm-node.0 (remote-exec): Cannot connect to the Docker daemon. Is the docker daemon running on this host?
aws_instance.swarm-node.0 (remote-exec): flag needs an argument: --token
aws_instance.swarm-node.0 (remote-exec): See 'docker swarm join --help'.

      

Code that uses --token

provisioner "remote-exec" {
  inline = [
    "echo ===================================",
    "echo JOIN-TOKEN: `docker -H ${aws_instance.swarm-manager.0.private_ip} swarm join-token -q` ",
    "echo ===================================",
    "echo ===================================",
    "sudo docker swarm join ${aws_instance.swarm-manager.0.private_ip}:2377 --token $(docker -H ${aws_instance.swarm-manager.0.private_ip} swarm join-token -q worker)"
  ]
}

      

Exiting the command above:

aws_instance.swarm-node.1 (remote-exec): Usage:  docker swarm join-token [-q] [--rotate] (worker|manager)

aws_instance.swarm-node.1 (remote-exec): Manage join tokens
aws_instance.swarm-node.1 (remote-exec): JOIN-TOKEN:
aws_instance.swarm-node.1 (remote-exec): ===================================
aws_instance.swarm-node.1 (remote-exec): ===================================
aws_instance.swarm-node.1 (remote-exec): ===================================
aws_instance.swarm-node.1 (remote-exec): ===================================
aws_instance.swarm-node.1 (remote-exec): ===================================
aws_instance.swarm-node.1 (remote-exec): Cannot connect to the Docker daemon. Is the docker daemon running on this host?
aws_instance.swarm-node.1 (remote-exec): flag needs an argument: --token

      

What to do to $(docker -H ${aws_instance.swarm-manager.0.private_ip}

return the token.

+3


source to share


1 answer


First, the fourth line of code is incomplete; You must specify which token you want to print [worker | manager]



Make sure the daemon is docker

running for both the manager and worker instances. And that your firewall rules are correctly set in both instances.

0


source







All Articles