Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localhost refuses connection with docker

I'm totally new to docker and I tried to run the example image from the "get started" tutorial.

My OS is Windows 10 Home (64 bit) and I used Docker Toolbox to install it. I created the 3 files like the demo told me to do and copied the content into them to avoid typing errors. When I start the image with docker run -p 4000:80 friendlyhello

there seems to be no problem, but when I try to connect in the browser with localhost:4000 the browser (Google Chrome most actual version) tells me that localhost refuses the connection. Even with Microsoft Edge the same error appears.

I also tried to change the windows firewall with an ingoing rule to allow the docker-engine.exe all ports, but it did not help.

Has anyone a hint for me how to solve the problem? I really want to get the example run :-)

Link to the get started example: https://docs.docker.com/get-started/part2/#pull-and-run-the-image-from-the-remote-repository

The docker process is also running: enter image description here

Update: It seems that I had the wrong version of OracleVM VirtualBox installed, and that the starting of the default VM didn't work because of an error. I installed a newer version and started the default image again and it worked.

After starting the docker container with: docker run -d -p 4000:80 friendlyhello

I was able to call the demo app inside the VirtualBox with port 4000:enter image description here

unfortunately this leaves me behind totally confused about how docker should work :-/. I thought after running docker I would be able to access it on my Windows OS because it's just another process but now it seems I still need a virtual machine? Can someone please explain me what I'm missing at this point?

like image 524
the hand of NOD Avatar asked Nov 21 '25 05:11

the hand of NOD


1 Answers

You need to run the following command with your container name to obtain the IP for the container.

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name>

You can then access the container http://IP_Obtained:Port.

Detailed Explanation can be found at https://docs.docker.com/docker-for-windows/troubleshoot/#limitations-of-windows-containers-for-localhost-and-published-ports

like image 97
priyaranjan Avatar answered Nov 23 '25 01:11

priyaranjan