Can't connect to container on localhost with port mapping

Hi
Hope to find some help here.
I’m trying torun a windows container on my windows machine. and would like to connect to it via localhost.
For example the container below.

docker run -d -p 8000:80 --name demo microsoft/dotnet-samples:aspnetapp_

I would like to be able to access it via chrome on http://localhost:8000 i can see the container is starting and output is written in the console but windows i can’t get a site using localhost. If I use the container ip then it works just fine.

Windows 10 version
10.0.17134 Build 17314

docker info
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 1
Server Version: 18.03.1-ce
Storage Driver: windowsfilter
Windows:
Logging Driver: json-file
Plugins:
Volume: local
Network: ics l2bridge l2tunnel nat null overlay transparent
Log: awslogs etwlogs fluentd gelf json-file logentries splunk syslog
Swarm: inactive
Default Isolation: hyperv
Kernel Version: 10.0 17134 (17134.1.amd64fre.rs4_release.180410-1804)
Operating System: Windows 10 Enterprise
OSType: windows
Architecture: x86_64
CPUs: 12
Total Memory: 39.93GiB
Name: ******
ID: Q6EP:QU7P:LHME:OIM4:WM2S:QKR4:AYFJ:CNMT:LE6Q:DFO4:IJAK:BPVY
Docker Root Dir: C:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: -1
Goroutines: 37
System Time: 2018-06-20T15:54:52.1709325+02:00
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

Solved by switching to linux containers and back to windows containers

1 Like

Can u explain me in detail coz i am experiencing the same issue…I dont get what a container ip is?are u talking about the ip displayed at the top of docker toolbox as container’s ip?

if you inspect the container and grap the ip4 fcan/could hit the container on that
docker inspect containername or containerid

Thankyou @ istern
Yes i tried that as follows:
$ docker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ b65e8cf8e28d
172.17.0.4

But still…
$ curl 172.17.0.4
curl: (7) Failed to connect to 172.17.0.4 port 80: Timed out

I am using windows 10 Home and dockertoolbox ## if it helps…

Can u pls figure it out for me coz i am stuck with this for weeks…

1 Like

Note that you can’t connect to that IP address from another host and it’s not constant if a container stops and restarts. There are better ways to reach a container (using docker run -p to publish a port on the host; using Docker’s internal DNS service to communicate between containers).

In short: I’d suggest never running docker inspect to find a container’s private IP address: it’s just not useful.

1 Like

If you’re using Docker Toolbox then any port you publish with docker run -p will be published on the Toolbox VM’s private IP address. docker-machine ip will tell you. It is frequently 192.168.99.100.

This isn’t prominent in Docker’s documentation, but it does at least show up in the excellent Get Started, Part 2: Containers tutorial. (I couldn’t find this rather important note anywhere around Toolbox Overview, for instance.)

8 Likes

Thank you for ur response David Maze…The actual problem i am encountering is that i have containerized a simple basic php app just with a echo"hello world".It is containerized and is listed with docker ps…Now when I tried to view it uing 192.168.99.100:8080 it says “refused to connect” or “forbidden”…So what am i missing…

I have the detailed form of the same issue in the given link

And I also tried with tutorials available in JavaTpoint

Yet I cant fix this…

I see you found a solution that works.
For others, something to try, is to disable IIS on the host machine (when doing local development).
that fixed a similar issue that I experienced when setting up my first containers

it still does not work for me. windows 10 host did as what is mentioned here .
this is how container was created

docker run --rm -it -v ${PWD}:/api -p 8484:234 microsoft/dotnet:2-sdk

If you’re using (Docker Toolbox), then any port you publish with (docker run -p) will be published on the Toolbox VM’s private IP address. Command (docker-machine ip) will tell you the correct IP address to use. It is frequently 192.168.99.100. Then you can browse to (192.168.99.100:8080) instead of (localhost:8080).

6 Likes

Woked for me. Thanks!

Thank you! That was my solution

Thanks a lot man… you saved me a lot of time …

great !
worked for me

Thanks a lot :slight_smile: … It worked…!!

Thank you this solved my problem.

Thanks, this also solved my problem

this answer have just saved my day mate. I through there is something wrong with me already…