Trouble connecting to apache webserver on Docker container from host

Hi, I’m on Windows 10, I’ve installed Docker for Desktop and I have an Ubuntu server that I’m working on in a container called ‘dev01’.

I’ve started the container with:

docker start dev01

Then I execute:

docker network inspect bridge

From this I can see the IP address of ‘dev01’ is 172.17.0.2/16.
I was hoping to access the website on the server by putting the ip address 172.17.0.2 straight into my browser but it does not connect. When I ping 172.17.0.2 from Windows cmd I get time outs.

I know the page is up and running on the container as from within the container I can use ‘lynx 172.17.0.2’ to view the page.

Is there a way to access a container from the host’s web browser?

EDIT:

Just noticed when I run ipconfig I have a DockerNAT adapter but it has no gateway:

   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Is that significant?

Thanks
bbw

Hi,
I’ve been looking at https://docker-curriculum.com/ and using his pre-made example I can see that the container starts up with ports exposed and I can access it…

 docker run -d -P --name static-site prakhar1989/static-site

If I do the same with one of my images (Ubuntu with Apache and PHP) the container exits immediately and I can’t start it. Can anyone explain this as I’m having trouble tracking the reason for this down.
Thanks.

Hi

In your docker run command, you have -P, which maps to RANDOM local ports, if you use:

docker port static-site

It will give you something like:

11333/tcp → 0.0.0.0:80

which means, that you need to access: http://localhost:11333 (in my case) to access the port 80 running in the container.

1 Like

Thanks, I finally got to a solution by starting a container as follows:
docker run -i -p 808:80 -td image_name
Where 808 is the port on the host and 80 the port in the container that I want to be pused out to 808.
Then I can access the webserver with:
localhost:808
This is working for me at the moment.

1 Like