Search code examples
dockerwindows-7localhostdocker-machinedocker-toolbox

Container is not available on localhost in Windows Docker Toolbox


I try to connect to my container on localhost/127.0.0.1/0.0.0.0 but site can’t be reached.

Details:

$ docker run -d -p 80:80 nginx:alpine

$ docker ps
CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS              PORTS
                                                                NAMES
d5b465ed1b18        nginx:alpine                            "nginx -g 'daemon of"   6 minutes ago       Up 6 minutes        0.0.0.
0:80->80/tcp                                                   quizzical_swirles
798b40ceec77        10.36.7.241:5000/facileexplorer:0.3.8   "/usr/bin/supervisor"   9 minutes ago       Up 9 minutes        4444/t
cp, 0.0.0.0:3838->3838/tcp, 0.0.0.0:8787->8787/tcp, 5900/tcp   vigilant_banach

I followed this tutotial: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/:

$ docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' d5b465ed1b18
<no value>

but it doesn't return port.

And I also helped myself with this guide: https://www.iancollington.com/docker-and-cisco-anyconnect-vpn/ because some of my docker images are on private registry, so I did following steps:

  1. PATH=$PATH:"C:\Program Files\Oracle\VirtualBox"; export PATH
  2. export DOCKER_HOST="tcp://127.0.0.1:2376"
  3. docker-machine stop default
  4. VBoxManage modifyvm "default" --natpf1 "docker,tcp,,2376,,2376"
  5. docker-machine start default
  6. alias docker='docker --tlsverify=false'

Could you help?


Solution

  • When you are using Docker Toolbox, running docker run -p 80:80 can be misleading. It means it will forward the port 80 of your container to the port 80 of your Docker machine, not the Windows host!

    If you want to access the container through your Windows host, you also need to forward port 80 of your Docker machine to that host.

    I see you are using VirtualBox, which allows you to do that by adding an entry in Settings > Network > Advanced > Port Forwarding.

    Example tutorial with images: https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/