当我们想执行 eval $(docker-machine env) 来加载 docker 服务器的环境变量时,却出现如下错误:

Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": dial tcp 192.168.99.100:2376: i/o timeout
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which will stop running containers.

根据提示,我们执行 docker-machine regenerate-certs,这次提示:

Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

This machine has been allocated an IP address, but Docker Machine could not
reach it successfully.
SSH for the machine should still work, but connecting to exposed ports, such as
the Docker daemon port (usually <ip>:2376), may not work properly.
You may need to add the route manually, or use another related workaround.
This could be due to a VPN, proxy, or host file configuration issue.
You also might want to clear any VirtualBox host only interfaces you are not using.

看起来仍然不行,仍旧是连接不到服务器,那服务器到底能不能连上呢?用 docker-machine ssh 竟然可以!让我们重启一下 docker-machine restart 试试。仍然不行。

那该怎么办?经过一番搜索,很多人都出现过这个问题,出现的情境基本和我一致——docker 服务器(虚拟机)所处网段与其他网卡的网段重叠了,导致连接不上。

我的情况是,家用路由器的网段和 docker-machine create 时默认使用的网段重叠了,所以每次回家再回到公司就会发现 docker 废掉了,一开始只能删掉重建虚拟机,后来发现了以下三种解决方案:

  1. 关掉 TLS 检查。不推荐。
  2. 创建虚拟机时指定其他网段:docker-machine create -d virtualbox --virtualbox-hostonly-cidr "192.168.90.1/24" default
  3. 修改其他网卡的网段,然后删掉 docker 虚拟机使用的网卡,再执行 docker-machine start,这会重建网卡。

转载于:https://my.oschina.net/tridays/blog/810568

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐