简体   繁体   中英

Running .NET framework console-app service on Docker

I'm trying to get a service on-boarded to Docker containers. Target Framework - .NET Framework 4.6.1 Output type - Console Application

When I initially tried to right click -> Add -> Docker Support on the project in the Visual Studio 2017 sln I got a prompt "You cannot add Docker support to this project type"

I went ahead and created a Dockerfile by hand and placed it in the root. This is what it looks like:

FROM microsoft/windowsservercore

SHELL ["powershell", "-command"]

RUN Add-WindowsFeature NET-Framework-45-ASPNET, Web-Asp-Net45

EXPOSE 80
EXPOSE 5000
EXPOSE 13134

ADD ./bin/Debug/net461/win7-x64 .
COPY ./bin/cert-that-needs-to-be-installed.pfx /cert-that-needs-to-be-installed.pfx

RUN $Secure_String_Pwd = ConvertTo-SecureString "thePasswordToTheCert!" -AsPlainText -Force; \
    Import-PfxCertificate -FilePath .\cert-that-needs-to-be-installed.pfx  -CertStoreLocation Cert:\LocalMachine\My -Exportable -Password $Secure_String_Pwd;

ENV ASPNETCORE_ENVIRONMENT="Development"
ENTRYPOINT ["./ServiceName.exe"]

Upon doing the following, I was able to successfully create an image and also a container with the service running on it: (the prod version listens on port 5000 while the test one listens on 13134 and those ports are also open in my localhost Firewall)

docker build -t ServiceName .; docker run -p 5000:5000 -p 13134:13134 -it ServiceName

I am able to get the ip of the container by doing this:

docker inspect <containerId>

Now when I try to test the service by doing a HttpGet call to an API using Postman I don't get a response. I have the docker container open in my cmd prompt and I don't see my request coming in either.

My service works fine on a Windows VM. Since my GET calls don't even seem to reach the container I fear I am doing the port mapping wrong/or is it something else?

据我所知,您不需要容器的ip,端口已投影在localhost上,当您对localhost:5000 / localhost:13134进行REST调用时,应该会得到响应

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM