0

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.

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

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

  • 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)

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

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

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

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

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

Any ideas? Thanks! Peter

4

2 回答 2

4

我在这里的另一个问题中找到了答案。

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

docker-machine ip default
于 2017-01-11T08:54:55.503 回答
0

当您在 VM 上运行时,您需要从此处遵循此 docker 文档。

之后运行以下命令来检查你的虚拟机的 IP 地址。

docker-machine ip default

启动 nginx 并在浏览器中点击 [ip default address]:port。有用!

于 2018-08-26T21:57:51.920 回答