0

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.

Screenshot of my errors

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.

Magnus
  • 589
  • 8
  • 26
  • Have you tried running `docker ps` and making sure that the container is running? If it is, connect to the shell with `docker exec -it container_id some_command` – Serey Jul 19 '17 at 11:31
  • Yes. The window on the right hand side in my screenshot is from powershell.exe inside the container. From there, I can retrieve the apache webpage with no problem. – Magnus Jul 19 '17 at 11:51
  • 1
    Your `Dockerfile` also have `EXPOSE 80` in it? – Grimmy Jul 19 '17 at 13:49
  • 1
    Also run `docker ps` and make sure the `PORTS` column actually displays the port mappings. It should display something like `0.0.0.0:8082->80/tcp` – Grimmy Jul 19 '17 at 13:52
  • 1
    It's also a very common mistake forgetting to rebuild a new image when making changes. Overall what you describe here looks perfectly sane. – Grimmy Jul 19 '17 at 13:54
  • 1
    Just noticed you are using `-dit`. Not sure what that will imply for the running container. `run -d` should be enough. – Grimmy Jul 19 '17 at 14:01
  • @Grimmy, yes I do have EXPOSE 80, and the `docker ps` command does display the correct port mapping. I don't quite understand what the `-i` and `-t` parameters do; they were a quick fix that I googled in order to not have the container quit immediately after it was run. – Magnus Jul 20 '17 at 06:20

1 Answers1

0

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.

Magnus
  • 589
  • 8
  • 26