本地主机不工作docker windows 10 [英] localhost not working docker windows 10

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

问题描述

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

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 docs 作为starter 和 构建 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 容器,并且如果您遵循 docker docs 示例,您应该会看到其中列出的名称为 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.

回答您的第一个问题(在 docker for windows 中使用 localhost 访问 docker 容器),在 Windows 主机中,由于默认 NAT 网络堆栈的限制,您无法使用 localhost 访问容器.访问此链接.似乎 docker 文档尚未更新,但此问题仅存在于 Windows 主机中.

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天全站免登陆