MeLight
MeLight

Reputation: 5565

Can not access nginx container on a local windows machine

I'm running an nginx container on a windows 10 machine. I've stripped it down to a bare minimum - an nginx image provided in the Docker hub. I'm running it using:

docker run --name ng -d -P nginx

This is the output of docker ps:

b5411ff47ca6 nginx "nginx -g 'daemon off" 22 seconds ago Up 21 seconds 0.0.0.0:32771->80/tcp, 0.0.0.0:32770->443/tcp ng

And this is the IP I'm getting when doing docker inspect ng: "IPAddress": "172.17.0.2"

So, the next thing I'm trying to do is access the Nginx server from the host machine by opening http://172.17.0.2:32771 in browser of the host machine. This is not working (host not found etc).

Please advise

Upvotes: 10

Views: 12661

Answers (3)

Alex Sirota
Alex Sirota

Reputation: 93

I used the following command to map the internal port 80 on the running container to port 82 off localhost:

docker run --name webserver2 -d -p 82:80 nginx

accessing nginx image off localhost:82 works great.

The port you want to access from your local web browser is the first number before the :80 which is where nginx image runs virtually in the container.

There is lots of miscommunication out there on the issue -- it's a simple port mapping between the host machine (Windows you are running) and the container running on docker.

Upvotes: 2

Nikhil Pingle
Nikhil Pingle

Reputation: 746

  1. Follow this article... https://docs.docker.com/get-started/part2/#run-the-app
  2. And make sure your application is running not just docker.

docker run -d -p 4000:80 friendlyhello

After this on Windows 10 host machine

  1. Worked http://192.168.99.100:4000/
  2. Not working: http://localhost:4000/

Upvotes: 5

Xiongbing Jin
Xiongbing Jin

Reputation: 12097

On windows, you are using Docker Toolbox, and the IP you need is 192.168.99.100 (which is the IP of the Docker Toolbox VM). The IP you got is the IP of the container inside the VM, which is not accessible directly from Windows.

Upvotes: 34

Related Questions