本地主机无法正常工作的docker Windows 10 [英] localhost not working docker windows 10

查看:108
本文介绍了本地主机无法正常工作的docker Windows 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS2017 Docker支持. VS为我创建了DockerFile,当我构建docker-compose文件时,它会创建容器并在172.x.x.x IP地址上运行该应用程序.但是我想在本地主机上运行我的应用程序.

I am using VS2017 docker support. VS created DockerFile for me and when I build docker-compose file, it creates the container and runs the app on 172.x.x.x IP address. But I want to run my application on localhost.

我做了很多事情,但没有任何效果.遵循 docker文档作为入门和构建Microsoft示例应用.第二个链接运行正常,但是尝试第一个链接方法时出现HTTP错误404.

I did many things but nothing worked. Followed the docker docs as a starter and building microsoft sample app . The second link is working perfectly but I get HTTP Error 404 when tried the first link approach.

感谢您的帮助.

推荐答案

要访问Docker Docs上发布的示例(您指出该示例不起作用),请执行以下步骤,

In order to access the example posted on Docker Docs, that you pointed out as not working, follow the below steps,

1-列出所有正在运行的docker容器

1 - List all the running docker containers

docker ps -a

运行此命令后,如果您正确遵循了docker docs示例,则应该能够查看当前正在运行的所有Docker容器,并且应该在其中看到名称为webserver的容器.

After you run this command you should be able to view all your docker containers that are currently running and you should see a container with the name webserver listed there, if you have followed the docker docs example correctly.

2-获取运行webserver容器的IP地址.为此,请运行以下命令.

2 - Get the IP address where your webserver container is running. To do that run the following command.

 docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" webserver

您现在应该获得运行webserver容器的IP地址,希望您熟悉此步骤,因为该步骤甚至可以在您附带问题的Microsoft示例应用示例中使用.

You should now get the IP address which the webserver container is running, hope you are familiar with this step as it was even available within the building Microsoft sample app example that you attached with the question.

访问运行上述命令后获得的IP地址,您应该会看到所需的输出.

Access the IP address you get once running the above command and you should see the desired output.

回答第一个问题(在Windows的docker中使用docker访问localhost中的docker容器),由于默认NAT网络堆栈的限制,在Windows主机中,您无法使用localhost访问容器.有关此问题的更详细说明,请访问以下

Answering to your first question (accessing docker container with localhost in docker for windows), in Windows host you cannot access the container with localhost due to a limitation in the default NAT network stack. A more detailed explanation for this issue can be obtained by visiting this link. Seems like the docker documentation is not yet updated but this issue only exists in Windows hosts.

与此同时也报告了一个问题-请遵循以下 链接 来查看.

There is an issue reported for this as well - Follow this link to see that.

希望这对您有所帮助.

编辑

此问题的解决方案似乎将在将来的Windows版本中提供.但是该版本发布后,Windows主机中就提供了此限制.跟随此链接-> https://github.com/MicrosoftDocs/Virtualization-Documentation/issues/181

The solution for this issue seems to be coming in a future Windows release. Yet that release comes out this limitation is available in Windows host. Follow this link -> https://github.com/MicrosoftDocs/Virtualization-Documentation/issues/181

这篇关于本地主机无法正常工作的docker Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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