[Solved] Windows container: Getting contact with container -portmapping and configuration

Hi!
I’m running a .NET Core web app with a .NET .4 dependency, so I’m running a windows server core container.
The container builds fine, runs fine, but I am unable to access the web from the host machine (windows 10), I’m guessing it is related to port mappings, but I’m not entirely sure. Ideally, I’d like to expose port 5000 on the image as well as using 5000 on the host, but using any sensible combination of ports is fine (for example 81 on host, 80 in container)

The Dockerfile consists of the following lines:

FROM microsoft/windowsservercore
COPY . c:\containerapp
WORKDIR c:\windows
RUN dism.exe /online /enable-feature /all /featurename:iis-webserver /NoRestart
RUN echo “Hello World - Dockerfilez” > c:\inetpub\wwwroot\index.html
ENV ASPNETCORE_URLS http://+:80
EXPOSE 80
EXPOSE 5000/tcp
CMD [ “cmd” ]

I am not at all sure this is a good/valid setup.

I start the container using the following statement:
docker run -idt -p 80:80 testcore:latest
docker run -idt -p 81:80 testcore:latest
docker run -idt -p 5000:5000 testcore:latest
docker run -idt -p 5000:80 testcore:latest
no matter what, I’m unable to curl http:localhost:xx there xx is the port number, like 80, 81 and 5000 from the examples above. Same goes from trying localhost:5000 (or other ports) in a browser on the host.
If I connect to the container, I’m able to successfully curl http://localhost, but not curl http://localhost:5000

Inside the container, I run netstat, here is the output. I notice that post 5000 is missing:

PS C:> netstat -ano

Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1096
TCP 0.0.0.0:5985 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:47001 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:49152 0.0.0.0:0 LISTENING 408
TCP 0.0.0.0:49153 0.0.0.0:0 LISTENING 1200
TCP 0.0.0.0:49154 0.0.0.0:0 LISTENING 1264
TCP 0.0.0.0:49155 0.0.0.0:0 LISTENING 724
TCP 0.0.0.0:49157 0.0.0.0:0 LISTENING 824
TCP 172.29.209.194:49167 40.77.226.250:443 ESTABLISHED 1476
TCP [::]:80 [::]:0 LISTENING 4
TCP [::]:135 [::]:0 LISTENING 1096
TCP [::]:5985 [::]:0 LISTENING 4
TCP [::]:47001 [::]:0 LISTENING 4
TCP [::]:49152 [::]:0 LISTENING 408
TCP [::]:49153 [::]:0 LISTENING 1200
TCP [::]:49154 [::]:0 LISTENING 1264
TCP [::]:49155 [::]:0 LISTENING 724
TCP [::]:49157 [::]:0 LISTENING 824
UDP 0.0.0.0:5353 : 1396
UDP 0.0.0.0:5355 : 1396
UDP [::]:5353 : 1396
UDP [::]:5355 : 1396
PS C:>

also, GetNetTCPConnection shows no trace of port 5000;

PS C:> Get-NetTCPConnection

LocalAddress LocalPort RemoteAddress RemotePort State AppliedSetting OwningProcess


:: 49157 :: 0 Listen 824
:: 49155 :: 0 Listen 724
:: 49154 :: 0 Listen 1264
:: 49153 :: 0 Listen 1200
:: 49152 :: 0 Listen 408
:: 47001 :: 0 Listen 4
:: 5985 :: 0 Listen 4
:: 135 :: 0 Listen 1096
:: 80 :: 0 Listen 4
172.29.209.194 49167 40.77.226.250 443 TimeWait 0
0.0.0.0 49157 0.0.0.0 0 Listen 824
0.0.0.0 49155 0.0.0.0 0 Listen 724
0.0.0.0 49154 0.0.0.0 0 Listen 1264
0.0.0.0 49153 0.0.0.0 0 Listen 1200
0.0.0.0 49152 0.0.0.0 0 Listen 408
0.0.0.0 135 0.0.0.0 0 Listen 1096

I’m really in a blind here, I find a lot of documentation on Linux containers, and a lot of samples. I have a working linux sample preset, but I’d have to switch docker to linux again to pull it up.

And hints to changes in DockerFile, docker run statement or other tips would be greatly appreciated.

Kind regard,
Audun

Solution found at Published Ports On Windows Containers Don't Do Loopback
Summary: connect to the container, get the IP address. Go back to the host and curl the IP.