111

So I'm using Docker Toolbox because I don't have Hyper-V on my machine since it's not Windows 10 pro. Everything seems to work fine, but when I try to go on my browser 0.0.0.0:80 it always returns me: This site can’t be reached

But when I run the command: docker container ps I get the following: 0.0.0.0:80->80/tcp meaning that this address should work. I searched across stackoverflow and github issues. Now I'm stuck.

Am I missing something?

Thanks, Mark

EDIT:

Using docker-machine ip default returns me 192.168.99.100. I run that on port 80. I still get the same result except that the address becomes the container id: https://fd677edg12

I run that command on cmd to find my ipv4: cmd /k ipconfig /all. Put the result with the port and it returns the same thing: https://fd677edg12

3
  • 1
    0.0.0.0 is not an actual address, it means that the port was bound to all of the docker's host (your windows computer) interfaces. Try localhost:80 or whatever ip address your computer has : 80
    – fvu
    Mar 17, 2017 at 20:04
  • @fvu I still get "this site cannot be reached". I also tried docker-machine default ip -> 192.168.99.100 So I put this in the address: 192.168.99.100:80 I still get the same reasult.
    – Mark
    Mar 17, 2017 at 20:18
  • 1
    If you are getting redirected -- it's your app that is broken. Assuming docker is running on the same computer, you should be able to localhost:80 Mar 17, 2017 at 20:53

7 Answers 7

188

Docker Toolbox doesn't get as many conveniences as Docker for Windows, but you're correct in using it since you're on Home edition.

In Toolbox, nothing will be localhost, and will be 192.168.99.100 by default, since it's running a Linux VM in VirtualBox.

So if you run docker run -p 80:80 nginx

(notice I had to publish a port for 192.168.99.100 to listen on that port)

Then going to http://192.168.99.100 should work.

3
  • Thanks for the response. I'm following your steps except added docker run -p 80:80 -d nginx. I go to the address and it redirects me to https://dev/, again it says that the site cannot be reached. I also wanted to verify if I had anything is the hosts file (although I know it's not localhost). I commented everything there.
    – Mark
    Mar 20, 2017 at 18:49
  • After several attempts, I finally got it working. Sadly, I'm not too sure what was the problem.
    – Mark
    Apr 18, 2017 at 2:53
  • 2
    Bonus info: The Docker Toolbox (used in Windows 7, 8, 8.1, and 10 Home) is really just a startup script wrapped around docker-machine cli. You can use docker-machine --help to see what you can do to manage the VirtualBox VM (or create more). Aug 9, 2018 at 20:44
67

I initially had a few issues with accessing my Applications at localhost:8080 while using DockerToolBox and OracleVM VirtualBox.

In VirtualBox:

  1. Click the appropriate machine (probably the one labeled "default")
  2. Settings
  3. Network > Adapter 1 > Advanced > Port Forwarding
  4. Click "+" to add a new Rule
  5. Set Host Port 8080 & Guest Port 8080; be sure to leave Host IP and Guest IP empty

Run the command:

docker run -p 8080:8080 ${image_id}
2
  • Due to CORS setup on the remote API, I have to run as localhost:8080. So great it's so simple, thanks!
    – phazei
    Nov 18, 2017 at 5:23
  • Also, make sure you don't mess things up with other stuff listening on this port already or localhost/127.0.0.1 entries in your hosts file (C:\Windows\System32\drivers\etc\hosts) - I had to get both in check before it worked for me ;-)
    – msa
    Aug 28, 2019 at 19:11
47

I was following docker for windows tutorial in https://docs.docker.com/docker-for-windows/#set-up-tab-completion-in-powershell and got stuck in step #6 when test nginx in the web browser. Seems I faced a similar problem since I also use Windows Home and don't have Hyper-V. My workaround is quite simple:

  1. check your docker IP default

$ docker-machine ip default

192.168.99.100

  1. Go to Oracle Virtual Machine to set for port forwarding. Make sure the network setting is NAT, and add port forwarding. Host IP: 127.0.0.1, Guest IP: 192.168.99.100, port all set to 80 like this

  2. Try again to your browser and run http://localhost or http://127.0.0.1 (can add the port 80 also). It should run.

The thing is that the nginx IP is meant to be accessible within the docker Virtual Machine, so that we need that port forwading setting in order to access it directly in the host machine's browser

1
  • 2
    I needed a case when HOST:CONTAINER ports are different, e.g. docker run --detach --publish 8081:80 --name webserver nginx. Found that in this case I had to forward HOST port only, i.e. in VirtualBox settings Host IP=127.0.0.1; Host Port=8081; Guest IP=192.168.99.100; Guest Port=8081, not 80 as I supposed before. Looks like in my Windows 7 machine with Docker Toolbox Docker forwards from container port 80 to 192.168.99:8081 and I forward from 192.168.99:8081 to localhost:8081 because 192.168.99:8081 does not show anything in web-browser.
    – and1er
    Apr 29, 2019 at 10:23
14

You can use localhost instead of '192.168.99.100' by following the instructions:

Step #01:

docker-machine ip default

You will see the default IP

Step #02:

docker-machine stop default

Step #03:

  1. Open VirtualBox Manager (from the start programs in windows search for VirtualBox Manager)
  2. Select your Docker Machine VirtualBox image (e.g.: default)
  3. Open Settings -> Network -> Advanced -> Port Forwarding
  4. Add your app name, the desired host port and your guest port i.e, app name : nginx, host: 127.0.0.1, host port: 80, guest port: 80

Step #04: Now you’re ready to start your Docker Machine by executing the following:

docker-machine start default

Then just start your Docker container and you will be able to access it via localhost.

Have a look here for details.

2

To map the ports expected to localhost instead of hitting the docker-machine IP directly, you can use the VirtualBox CLI.

If the docker-machine VM (here called default) is running, add and delete rules like this:

> VBoxManage.exe controlvm "default" natpf1 "nginx,tcp,,8888,,8888"
> VBoxManage.exe controlvm "default" natpf1 delete nginx

If the VM is not running, or you want to stop before altering it:

> docker-machine stop
> VBoxManage.exe modifyvm "default" --natpf1 "nginx,tcp,,8888,,8888"
> VBoxManage.exe modifyvm "default" --natpf1 delete "nginx"
> docker-machine start

Where the format of the port forwarding rule is [<name>],tcp|udp,[<hostip>],<hostport>,[<guestip>], <guestport>.

Note that in VirtualBox, you want to map to the host port of Docker map, not the internal container port. You're mapping host -> VM, then Docker maps VM -> container.

See the VirtualBox docs.

2

This is another easy way to avoid typing the ip 192.168.99.100. Go to C:\Windows\System32\drivers\etc\hosts and add at the end of the file:

192.168.99.100 docker.awesome or any name of your liking.

Save the file (You need to have admin rights so make sure you right click on the file and run as administrator to be able to save it when you edit it).

Go to your chosen domain name, docker.awesome:8080 in this case and there you have it.

0

After lot of trials, I was able to get this bulletin board.

  1. The docker run command I used - docker run -p 4680:8080 --name bb bulletinboard:1.0 Here, 4680 is localhost port number. 8080 is container port number, the port at which the container will be listening. This port number is mentioned in the EXPOSE command in the Dockerfile.

  2. Then, go to web-browser and type 192.168.99.100:4680

Here, 192.168.99.100 is the docker machine IP address (use command -> docker-machine ip)

  1. After this, your browser page should open to -

enter image description here

Hope this helps you all!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.