docker遇到问题五:swarm 添加worker机报错,信息如“Error response from daemon: rpc error: code = Unavailable desc = ”

参照 官方文档 part4的示例,添加worker机报错,整个过程如下:

创建两台VM

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine create --driver virtualbox myvm1
Running pre-create checks...
Creating machine...
(myvm1) Copying /Users/cappuccinooo/.docker/machine/cache/boot2docker.iso to /Users/cappuccinooo/.docker/machine/machines/myvm1/boot2docker.iso...
(myvm1) Creating VirtualBox VM...
(myvm1) Creating SSH key...
(myvm1) Starting the VM...
(myvm1) Check network to re-create if needed...
(myvm1) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env myvm1
cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine create --driver virtualbox myvm2
Running pre-create checks...
Creating machine...
(myvm2) Copying /Users/cappuccinooo/.docker/machine/cache/boot2docker.iso to /Users/cappuccinooo/.docker/machine/machines/myvm2/boot2docker.iso...
(myvm2) Creating VirtualBox VM...
(myvm2) Creating SSH key...
(myvm2) Starting the VM...
(myvm2) Check network to re-create if needed...
(myvm2) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env myvm2

查看VM创建情况

cappuccinooos-MacBook-Pro:~ cappuccinooo$ docker-machine ls
NAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
myvm1   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.05.0-ce
myvm2   -        virtualbox   Running   tcp://192.168.99.101:2376           v18.05.0-ce

创建Swarm集群manager机

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine ssh myvm1 "docker swarm init"
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on eth0 and 192.168.99.100 on eth1) - specify one with --advertise-addr
exit status 1

官方文档中写明了如果出现类似报错,需要指定对应IP地址和端口,调整后的命令如下:

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100:2377"
Swarm initialized: current node (56rvohie5wacjc9pt4y96pfbd) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-15dtlp88h8s12s6e76l8v3vtvj5rm32wor0rg36bjongv36qd3-82m58k6bp2dk2ugez1ksp5p2w 192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

查看Swarm manager机创建情况

cappuccinooos-MacBook-Pro:~ cappuccinooo$ docker-machine env myvm1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/cappuccinooo/.docker/machine/machines/myvm1"
export DOCKER_MACHINE_NAME="myvm1"
# Run this command to configure your shell:
# eval $(docker-machine env myvm1)

可以看到manager相关信息,说明创建是成功的

创建Swarm集群worker机

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine ssh myvm2 "docker swarm join --token SWMTKN-1-15dtlp88h8s12s6e76l8v3vtvj5rm32wor0rg36bjongv36qd3-82m58k6bp2dk2ugez1ksp5p2w 192.168.99.101:2377"
Error response from daemon: rpc error: code = Unavailable desc = grpc: the connection is unavailable
exit status 1

报错原因排查了下,是IP地址写错了,应该写的是manager机的IP地址,将192.168.99.101改成192.168.99.100问题就解决了,如下:

cappuccinooos-MacBook-Pro:part3 cappuccinooo$ docker-machine ssh myvm2 "docker swarm join --token SWMTKN-1-15dtlp88h8s12s6e76l8v3vtvj5rm32wor0rg36bjongv36qd3-82m58k6bp2dk2ugez1ksp5p2w 192.168.99.100:2377"
This node joined a swarm as a worker.

查看Swarm worker机创建情况

cappuccinooos-MacBook-Pro:~ cappuccinooo$ docker-machine env myvm2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="/Users/cappuccinooo/.docker/machine/machines/myvm2"
export DOCKER_MACHINE_NAME="myvm2"
# Run this command to configure your shell:
# eval $(docker-machine env myvm2)

你可能感兴趣的:(docker)