[英]Running .NET framework console-app service on Docker
I'm trying to get a service on-boarded to Docker containers. 我正在尝试将服务加载到Docker容器中。 Target Framework - .NET Framework 4.6.1 Output type - Console Application
目标框架-.NET Framework 4.6.1输出类型-控制台应用程序
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" 当我最初尝试在Visual Studio 2017 sln中的项目上右键单击->添加-> Docker支持时,出现提示“您不能向该项目类型添加Docker支持”
I went ahead and created a Dockerfile by hand and placed it in the root. 我继续手工创建了一个Dockerfile并将其放置在根目录中。 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) 完成以下操作后,我能够成功创建一个映像以及一个运行有服务的容器:(生产版本侦听端口5000,而测试版本侦听13134,并且这些端口也在本地防火墙中打开)
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: 我可以通过执行以下操作获取容器的IP:
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. 现在,当我尝试通过使用邮递员对API进行HttpGet调用来测试服务时,没有得到响应。 I have the docker container open in my cmd prompt and I don't see my request coming in either.
我在cmd提示符下打开了docker容器,但我都没有看到我的请求。
My service works fine on a Windows VM. 我的服务在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?
由于我的GET调用似乎都未到达容器,因此我担心端口映射错误/或者还有其他问题吗?
据我所知,您不需要容器的ip,端口已投影在localhost上,当您对localhost:5000 / localhost:13134进行REST调用时,应该会得到响应
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.