Nick W
Nick W

Reputation: 907

Connect to docker container on Windows

I've read this post and I've tried adding ports: "7080:7080" in docker-compose.yml but still can't connect to the container using 172.18.0.2:7080 (btw I'm a docker newbie)

The container is one of several in a DockStation project on Windows 10. The image I'm using is for OpenLiteSpeed with WordPress.

The docker-compose.yml file contents is below:

version: '2'
services:
  gnome-3-28-1804:
    image: ubuntudesktop/gnome-3-28-1804
  firefox:
    image: jlesage/firefox
  browser-box:
    image: jim3ma/browser-box
  openlitespeed:
    image: litespeedtech/openlitespeed
    ports: 
     - "7080:7080"

Any ideas please?

UPDATE: IP 172.17.0.1 appears to be the default bridge gateway IP so I assume 172.18.0.2 for this container is in some way related to that; Docker and DockStation are both running locally on host 10.0.0.10 Not sure if the setup should even be using a bridge. http://localhost:7080/ says ERR_CONNECTION_REFUSED

UPDATE 2: I'm using Docker for Windows (Docker Desktop). Tried turning off the Windows firewall but makes no difference. Still getting ERR_CONNECTION_REFUSED for http://localhost:7080/ and http://10.0.0.10:7080/. There are 3 other containers in the project but not running, only the LiteSpeed one is running.

UPDATE 3: I created a new project and installed tutum/hello-world/ then ran the new container. The hello-world container is running and I've not found any error in the logs, but neither localhost nor 10.0.0.10 will connect, the error in Chrome is ERR_CONNECTION_REFUSED. Same if I run docker run -d -p 80 tutum/hello-world in Windows command prompt.

Upvotes: 1

Views: 4807

Answers (3)

Nick W
Nick W

Reputation: 907

This solution worked for me.

docker run -d -p 127.0.0.1:80:80 tutum/hello-world

Apparently you have to specify you want the port exposed under localhost. Then localhost entered in the browser address bar loaded the Hello World page - hurrah!

Once I changed the ports in docker-compose.yml to '127.0.0.1:80:80' then it also worked when run from DockStation.

Upvotes: 0

Konrad Botor
Konrad Botor

Reputation: 5033

I tried your Compose file on my system and it works as expected - I can access port 7080 both using my host's system IP and hostname and the container's IP and ports 80 and 443 using only the container's IP (since they're not mapped to any of the host's ports).

You did not specify whether you're using Docker for Windows or Docker Toolbox - DockStation works with both, but if you're using Docker Toolbox, then you'll have to use the virtual machine's IP or hostname to access port 7080, instead of localhost. If you're using Docker for Windows, then I do not understand what is going on - are you sure the containers are running?

As for where those IP's you mentioned come from - 172.17.0.1 is most likely your hosts IP on Docker's default bridged network. Docker-compose, by default, creates its own bridged networks for every project. In your case, in your project's network, your host's IP would be 172.18.0.1. You can view Docker's networks with command docker network ls and their details with docker network inspect <network-name>.

You should not use any of those IP's for any reason, since there's no guarantee they'll remain the same. If you need to connect from outside, map internal container ports to your Docker's host's ports, like you did with port 7080 and if you need containers to connect to each other - with docker-compose you can use service names as hostnames, without it you have to connect them to the same, non-default, bridged Docker network and use their container names as hostnames.

Upvotes: 1

svorcan
svorcan

Reputation: 340

What is this IP (172.18.0.2) representing? Is it a remote machine where DockStation is running?

If this is a case, check if this port is publicly available on that machine. You did add ports section to the Dockerfile which will map container's port to machine's port - but it is a matter whether e.g. firewall blocks outside access to that port.

I would first troubleshoot it by trying to access localhost:7080 from 172.18.0.2 machine - if it works, your Docker configuration is good and you need to look for the problem in that machine's configuration (e.g. firewall).

Upvotes: 1

Related Questions