本地主机拒绝与docker的连接 [英] localhost refuses connection with docker

查看:68
本文介绍了本地主机拒绝与docker的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是docker的新手,我试图从入门"教程中运行示例图像.

我的操作系统是Windows 10 Home(64位),我使用Docker Toolbox进行安装.我创建了3个文件,就像演示程序告诉我的那样,然后将内容复制到其中,以避免键入错误.当我开始用 docker run -p 4000:80 friendlyhello

似乎没有问题,但是当我尝试在浏览器中使用本地主机:4000浏览器(Google Chrome最实际的版本)告诉我localhost拒绝连接.即使使用Microsoft Edge,也会出现相同的错误.

我还尝试使用一个不变的规则来更改Windows防火墙,以允许docker-engine.exe拥有所有端口,但这并没有帮助.

有人对我有提示如何解决该问题吗?我真的很想让示例运行:-)

链接到入门示例:

更新:看来我安装了错误版本的OracleVM VirtualBox,并且由于错误而无法启动默认VM.我安装了新版本,然后再次启动默认图像,它可以正常工作.

使用以下命令启动docker容器后:docker run -d -p 4000:80 friendlyhello

我能够通过端口4000在VirtualBox内调用演示应用程序:

不幸的是,这使我完全不知道docker应该如何工作:-/.我以为在运行docker之后,我将能够在Windows OS上访问它,因为这只是另一个过程,但是现在看来我仍然需要虚拟机?有人可以给我解释一下我目前所缺少的吗?

解决方案

您需要使用容器名称运行以下命令来获取容器的IP.

  docker inspect --format ='{{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}}'< container_name> 

然后您可以访问容器 http://IP_Obtained:Port .

详细说明可以在

My OS is Windows 10 Home (64 bit) and I used Docker Toolbox to install it. I created the 3 files like the demo told me to do and copied the content into them to avoid typing errors. When I start the image with docker run -p 4000:80 friendlyhello

there seems to be no problem, but when I try to connect in the browser with localhost:4000 the browser (Google Chrome most actual version) tells me that localhost refuses the connection. Even with Microsoft Edge the same error appears.

I also tried to change the windows firewall with an ingoing rule to allow the docker-engine.exe all ports, but it did not help.

Has anyone a hint for me how to solve the problem? I really want to get the example run :-)

Link to the get started example: https://docs.docker.com/get-started/part2/#pull-and-run-the-image-from-the-remote-repository

The docker process is also running:

Update: It seems that I had the wrong version of OracleVM VirtualBox installed, and that the starting of the default VM didn't work because of an error. I installed a newer version and started the default image again and it worked.

After starting the docker container with: docker run -d -p 4000:80 friendlyhello

I was able to call the demo app inside the VirtualBox with port 4000:

unfortunately this leaves me behind totally confused about how docker should work :-/. I thought after running docker I would be able to access it on my Windows OS because it's just another process but now it seems I still need a virtual machine? Can someone please explain me what I'm missing at this point?

解决方案

You need to run the following command with your container name to obtain the IP for the container.

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name>

You can then access the container http://IP_Obtained:Port.

Detailed Explanation can be found at https://docs.docker.com/docker-for-windows/troubleshoot/#limitations-of-windows-containers-for-localhost-and-published-ports

这篇关于本地主机拒绝与docker的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆