Vladimir Iliev
Vladimir Iliev

Reputation: 1887

Docker inside Linux VM cannot connect to web application

My setup is the following:

Host: Win10
Guest: Ubuntu 15.10 (clean install, only docker and nodejs are added)
Base image: https://hub.docker.com/r/microsoft/aspnet/ 1.0.0-beta8-coreclr

Inside the guest I have installed Docker and created image (added sample webapp using yeoman to the image above). When I run the image inside container I can ping the container IP sucessfuly using the container IP from the linux (e.g. 172.17.0.2).

$sudo docker run -d -p 80:5000 --name web myapp

$sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "web"
172.17.0.2

$ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.060 ms
1 packets transmitted, 1 received, 0% packet loss, time 999ms

$curl 172.17.0.2:80
curl: (7) Failed to connect to 172.17.0.2 port 80: Connection refused

I can also connect to the container and execute commands like ping, however from the linux machine (guest in VirtualBox, host for docker) I cannot access the web app that is hosted inside the container as seen above. I tried several approaches like mapping to the host IP addresses etc, but none of them worked. Did anyone have ideas where to start from ? Is the issue comes from that the docker is installed inside VirtualBox machine?

Thank you in advance.

Edit: Here are the logs from the container:

Could not open /etc/lsb_release. OS version will default to the empty string.
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Upvotes: 3

Views: 1319

Answers (1)

Will Hogan
Will Hogan

Reputation: 919

Your command tells Docker to essentially proxy requests from port 80 of the Linux guest to port 5000 of the container. So the curl command you tried doesn't work because you're trying on port 80 on the container, while the container itself has a service listening on port 5000.

To connect to the container directly, you would use (on the Linux guest):

curl 172.17.0.2:5000

To access via the published port on the Linux guest (from your host):

curl (Linux guest IP)

Or (from the Linux guest):

curl localhost

Edit: This will also prove to be problematic:

Now listening on: http://localhost:5000

You'll want your app inside the container to bind to all interfaces (0.0.0.0) so it listens on the container's assigned IP. With localhost it won't be accessible.

You might find this example useful:

https://github.com/aspnet/Home/blob/dev/samples/1.0.0-beta8/HelloWeb/project.json

This line specifies that the app bind to all interfaces (using "*") on port 5004:

21            "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5004"

You'll need similar configuration.

Upvotes: 2

Related Questions