I used this official guide to set up Docker on a Windows 7 machine:
https://docs.docker.com/windows/started/
I successfully pulled an image from the docker hub and I can run my own docker image.
No I am stuck trying to run and access a webserver with docker on Windows. Apparently, behind boot2docker
I can't reach my docker container the way I was used to.
Once I added -p 3007:80
to the docker run
command, the port forwarding showed up in the container list (docker ps
) as 0.0.0.0:3007 -> 80
. And with -p 127.0.0.1:3007:80
I get a more meaningful ip address. I cannot, however, reach the container with a browser on the Windows host.
Moreover, docker inspect
does not reveal an ip address for the running container (which also seems wrong).
I also tried --net=host
to no avail.
Things changed more than just a little by now: Docker supports Windows natively and Boot2Docker or Docker Toolbox aren´t needed anymore. You should start with Windows 10 (or Windows Server 2016) now.
Throughout my Docker on Windows journey I developed a best practice to check, if a webserver is accessible:
docker run -d -p hostport:containerport imagename
)docker exec -it containerName powershell
ordocker exec -it containerName bash
, if you use Linux containers) and check, ifiwr http://localhost:80 -UseBasicParsing
gives you a good looking HTML and HTTP Status 200docker network inspect dockerNetworkName
, which´ll give you all your containers data including the internal IP addresses) and point your Browser tohttp://containerIP:containerPort
.http://localhost:containerPort
(this maybe doesn´t work for Windows containers, because the localhost loopback isn´t working - although it could work on newer versions of Windows 10/Server 2016)Things changed a little with the introduction of Docker Toolbox. Now you do not directly interact with
boot2docker
, but instead usedocker-machine
. Althoughboot2docker
still exists as VM there is no CLI-Tool any longer. It was replaced by Docker Machine.Thus you should be able to get hold of the VM's IP address by typing:
docker-machine ip <machine-name>
. If you do have the default installation your machine name will bedefault
.With
docker-machine active
you can have a look which VM is currently active. With that name you can also usedocker-machine inspect <machine-name>
.You can find more about Docker Machine in the official docs.