简体   繁体   English

在Docker上运行.NET Framework控制台应用服务

[英]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.

相关问题 在 Linux 应用服务上的 docker 容器中运行.Net Core 控制台应用 - Running .Net Core console app in docker container on Linux App Service 将 .NET Core 控制台应用程序作为服务运行,还是重做? - Running .NET Core console app as a service, or redo? .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container 通过C#console-app执行一些命令 - Execute a few commands via C# console-app Roslyn 无法与 .net 框架控制台应用程序和 Docker 一起正常工作 - Roslyn doesn't work correctly with .net Framework Console app and Docker MVC 中的 OAuth 2.0 Mailkit“身份验证失败”,但 c# 控制台应用程序工作正常 - OAuth 2.0 Mailkit “Authentication failed” in MVC, but c# console-app works fine 没有这样的文件或目录,在 .net core 中运行控制台应用程序时无法在 docker 容器中找到 Python.exe - No such file or directory, Unable to find Python.exe in docker container when running console app in .net core 有没有办法使用 System.media Soundplayer 发布在 .NET Framework 上运行的 C# 控制台应用程序? - Is there a way to publish a C# console app running on the .NET Framework with System.media Soundplayer? 如何在 Azure 应用服务上运行的 ASP.NET Framework 应用中禁用服务器 GC - How to disable Server GC in ASP.NET Framework App running on Azure App Service 作为Windows服务运行的控制台应用程序会引发错误 - Console App running as a Windows Service throws an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM