尝试连接https://index.docker.io时网络超时。

205

我刚刚按照他们的网页,安装了Docker-Toolbox

我从Docker QuickStart Terminal开始,并看到以下内容

                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/


docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

bash-3.2$ 

但是当我尝试执行docker pull hello-world时,我看到的是这个:

bash-3.2$ docker run hello-world
Unable to find image 'hello-world:latest' locally
Pulling repository docker.io/library/hello-world
Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/hello-world/images. You may want to check your internet connection or if you are behind a proxy.
bash-3.2$ 

有什么问题吗?

20个回答

483

今天早上我遇到了同样的问题,以下方法解决了我的问题:

$ docker-machine restart default      # Restart the environment
$ eval $(docker-machine env default)  # Refresh your environment settings

看起来这是由于Docker虚拟机进入了一个奇怪的状态。这里有一个开放的GitHub问题


3
这对我也有用... 但是,每次开启新的终端会话都需要重新运行它。 - THX1137
17
在我从工作局域网切换到家庭局域网时好像会发生这种情况。可能是由于在家中无法访问DNS服务器所导致的。 - taco
10
当我更换WiFi网络时,我可以确认这会导致它出现故障。重新启动Docker总是可以解决问题。 - Stephen Harrison
3
好的,针对我的情况,我必须包含 docker-machine regenerate-certs default 这个命令。 - rogeriopradoj
3
天啊,现在一切都有意义了。切换网络设置(wifi、lan、vpn、家庭网络、工作内部网络、iPhone等)会导致这些奇怪的问题。 - nils petersohn
显示剩余6条评论

41

我在Windows 10上安装了不需要Toolbox的Docker版本,需要启用Hyper-V。

对于Docker版本1.12,我需要进入任务栏,右键单击Docker图标,选择“设置”->“网络”,将DNS服务器设置为固定值,使用Google的DNS服务器8.8.8.8

更改此设置后,它终于可以工作了。


我刚刚切换到固定模式,然后又切回去并点击应用。不需要一直保持固定模式。 - Philip Tinney
在我的情况下,我安装了OpenDNS umbrella客户端,它将您的网络设置为使用127.0.0.1作为DNS。Docker似乎会复制您的网络卡设置,因此将localhost放入其自己的DNS设置中,这自然是行不通的。 - Richard Benson
在 Windows 10 上工作过。 - master

16

更简单的解决方案是在/etc/default/docker文件中添加以下条目:

export http_proxy="http://主机名:端口号/"

然后重新启动docker服务:

service docker restart


它本来只是一个“示例”代理服务器,没想到会引起混乱。 - pr-pal
2
对于CentOS系统,该文件位于/etc/sysconfig/docker。 - Priyank Desai
对于MacOS,我手动将代理配置输入到Docker Desktop的“首选项”->“代理”中。 - user1394

7

我在我的MAC(主机)上使用VBOX 5.10的Docker VM时遇到了问题,这是一个网络问题。简单的解决方法是向VBOX映像添加桥接网络。您可以使用VM中包含的NAT配置,但需要将ssh端口从50375更改为2375。


1
这是对我有效的方法(在Windows 10 Pro上使用VirtualBox 5.0.10r104061)。对于比我更新的新手,请注意您需要docker-machine stop default,然后在VirtualBox管理器中添加网络,然后docker-machine start default(必要时将default更改为您机器的名称)。我首先尝试了@Mark-Smith的简单重启+ eval env建议,但对我没有用。 - David Brown
@dbaOnTap,你是我的救命恩人啊!我被卡在这个问题上好几天了。我使用的系统是Windows 10 Home,虚拟机是最新的测试版本VirtualBox Latest Test Build (5.0.15-10594),docker toolbox也是最新的版本(1.10.0),只有这个方式对我有效。 - guychouk

7

2016年8月更新

使用Docker for Mac(版本1.12.0),会遇到以下问题:

  docker pull node
Using default tag: latest
Pulling repository docker.io/library/node
Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/node/images. You may want to check your internet connection or if you are behind a proxy.`enter code here`

通过更新我的MacBook Pro的无线网络设置,包括以下DNS条目,解决了这个问题:8.8.8.8

更多信息,请参见此(日期较旧的)问题,该问题提供了本答案。


4
sudo service docker stop
sudo service docker start

适用于我...

不知何故,sudo service docker restart 无效。

(RHEL7)


4

在Windows 7上,如果你认为自己在代理后面

  1. Logon to default machine

    $ docker-machine ssh default
    
  2. Update profile to update proxy settings

    docker@default:~$ sudo vi /var/lib/boot2docker/profile
    
  3. Append from the below as appropriate

    # replace with your office's proxy environment
    export"HTTP_PROXY=http://PROXY:PORT"
    export"HTTPS_PROXY=http://PROXY:PORT"
    
    # you can add more no_proxy with your environment.
    export"NO_PROXY=192.168.99.*,*.local,169.254/16,*.example.com,192.168.59.*"
    
  4. Exit

    docker@default:~$ exit
    
  5. Restart docker machine

    docker-machine restart default
    
  6. Update environment settings

    eval $(docker-machine env default)
    
以下步骤略有变动,但与故障排除指南中所述相同:https://docs.docker.com/toolbox/faqs/troubleshoot/#/update-varlibboot2dockerprofile-on-the-docker-machine

在我的情况下,这个方法可行,但我删除了 export"HTTP_PROXY=http://PROXY:PORT... HTTPS_PROXY...,因为网络是直接访问的,没有认证。 - Muka

2
我昨天遇到了完全相同的问题,但是所有“热门”的答案(比如将DNS修复为8.8.8.8)都没有对我起作用。最终,我偶然发现了这个链接,它解决了我的问题... https://github.com/docker/for-win/issues/16 在Docker for Windows、Windows 10和Hyper-V之间,在虚拟网络适配器创建过程中似乎存在问题。具体来说,您可能会得到两个“vEthernet(DockerNAT)”网络适配器。使用Get-NetAdapter "vEthernet (DockerNAT)"(在提升的PowerShell控制台中)检查此情况。如果结果显示多个适配器,则可以使用以下命令禁用并重命名它:
$vmNetAdapter = Get-VMNetworkAdapter -ManagementOS -SwitchName DockerNAT
Get-NetAdapter "vEthernet (DockerNAT)" | ? { $_.DeviceID -ne $vmNetAdapter.DeviceID } | Disable-NetAdapter -Confirm:$False -PassThru | Rename-NetAdapter -NewName "OLD"

然后打开设备管理器,删除已禁用的适配器(出于某种原因,您可以从此处执行此操作,但无法从“网络和共享中心”适配器视图中执行此操作)。


1
在Windows 10上,只需右键单击系统托盘的Docker图标->设置...->重置->重新启动Docker。

1
我假设您遇到了网络问题。你是否在代理后面?它是否可能过滤与docker.io的连接或阻止docker用户代理?
我安装了工具箱并运行了您的测试。这里一切都正常:
docker is configured to use the default machine with IP 192.168.99.101
For help getting started, check out the docs at https://docs.docker.com

bash-3.2$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

535020c3e8ad: Pull complete 
af340544ed62: Already exists 
library/hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:d5fbd996e6562438f7ea5389d7da867fe58e04d581810e230df4cc073271ea52
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/userguide/

bash-3.2$

我重新安装了Docker-Toolbox,现在它似乎可以工作了。 - daydreamer
1
我使用强制选项删除了我创建的现有机器,并重新创建了它 - 这很有效。docker-machine rm -f <machine_name> - user1189332

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接