Heads up: I'm a novice in both general web administration and Docker. My errors could be caused by something very stupid.
I am running Docker for Windows Server 2016 (the native variant). I have pulled and built a simple Docker base image with Nano Server and Apache 2.4 (nanoserver/apache24). I have made a container from this image and mapped the container port 80 to my local port 8082.
From inside the container, I can use Invoke-WebRequest -uri http://localhost:80
and retrieve the default apache document. However, I would also expect Invoke-WebRequest -uri http://localhost:8082
from outside the container to retrieve the same file. This does not work. I have also tried using the container NAT address, running Invoke-WebRequest -uri http://172.23.58.7:8082
. This does not work neither. What is it that I have misconfigured here?
Screenshot from my process below. PowerShell in host computer on the left, PowerShell inside container on the right.
EDIT: @Grimmy asked me in the comment section whether I do have EXPOSE 80
in my Dockerfile and whether docker ps
command displays my container with the expected port mapping. It's yes on both counts. My container runs with arguments -d -it
because it was a quick Google fix to the problem where the container exits immediately after launch. I know -i
"keeps STDIN open" and -t
"allocates pseudo-tty", but I frankly don't understand what either of those imply or whether it could be relevant to the problem.
EDIT2: I did not explicitly mention this in the original post, but it's worth noting that netstat -a -o
does not display a PID listening on port 8082. I would expect this to be the case. Should it be the case?
The first 50 lines or so of output is displayed in the screenshot.
I got the answer from 'artisticcheese' in the Docker Forums.
You can not connect to mapped IP address within container host itself. it’s bug in Windows implementation of WinNAT. You need get private IP address of container and connect to it using port number. Or you can access through public mapped port from another host on the same network, that shall work.
I connected from another host, and it worked immediately. I frankly don't know what the "private IP address" of the container is as opposed to the NAT address, so I couldn't proceed on the other tip.