如何连接到托管在 Docker Toolbox 中的容器? [英] How do I connect to a container hosted in Docker Toolbox?

查看:36
本文介绍了如何连接到托管在 Docker Toolbox 中的容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Docker 容器中运行我的 ASP.NET Core 1.1 Web API,但我无法从浏览器或 curl 连接到 Web API.为了进行故障排除,我还提供了标准的 nginx 和 Apache httpd 容器,但也无法连接到这些容器,因此我认为这是 Docker/Docker 工具箱/配置问题,而不是我的应用程序的问题.

I am attempting to run my ASP.NET Core 1.1 web API in a Docker container, but I cannot connect to the web API from a browser or curl. To troubleshoot, I have also brought up standard nginx and Apache httpd containers and cannot connect to these either, so I believe this is a Docker/Docker Toolbox/configuration issue rather than a problem with my application.

我将专注于我使用 nginx 和 Apache 所做的事情:

I'll focus on what I have done with nginx and Apache:

我在 Windows 7 Professional 上运行 Docker Toolbox,一切似乎都如我所愿.

I am running Docker Toolbox on Windows 7 Professional, and everything seems to work as I would expect.

  • Docker 命令都按预期工作
  • 我可以访问底层的 Windows 文件系统
  • 我可以从 curl http://localhost 得到预期的结果(如果我在 Windows 7 上启动默认的 IIS 网站)
  • Docker commands all work as expected
  • I can access the underlying Windows filesystem
  • I can get the expected results from curl http://localhost (if I start the default IIS website on Windows 7)

所以现在我关闭 IIS 并在容器中运行 nginx:

So now I shut down IIS and run nginx in a container:

$ docker run -d -p 80:80 nginx
45bb1f373c11b820d8431de3eb3bf222d57d412de53e8625f461b62c4279e644

Docker 现在显示 nginx 正在运行:

Docker now shows nginx running:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
45bb1f373c11        nginx               "nginx -g 'daemon off"   47 seconds ago      Up 48 seconds       0.0.0.0:80->80/tcp, 443/tcp   admiring_pike

但我无法连接 curl(在 Docker 工具箱命令提示符内)或 Windows 中的网络浏览器:

But I cannot connect with either curl (within the Docker Toolbox command prompt) or a web browser in Windows:

$ curl http://localhost
curl: (7) Failed to connect to localhost port 80: Connection refused

如果我运行 Apache 2.4 (httpd) 容器,我会得到完全相同的结果.

I get exactly the same results if I run an Apache 2.4 (httpd) container.

有什么想法吗?谢谢!彼得

Any ideas? Thanks! Peter

推荐答案

我在另一个问题中找到了答案此处.

I have found the answer in another question here.

因为 Docker Toolbox 在轻量级 Linux VM 上运行,所以它有自己的 IP 地址.需要使用 DOCKER_HOSTlocalhost 映射到 VM 或通过其 IP 地址访问 VM,使用命令找到:

Because Docker Toolbox is running on a lightweight Linux VM, it has its own IP address. One needs either to map localhost to the VM using DOCKER_HOST ir access the VM via it's IP address, found using the command:

docker-machine ip default

这篇关于如何连接到托管在 Docker Toolbox 中的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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