简体   繁体   English

将.NET Core Console应用程序构建到Docker中

[英]Build .NET Core Console Application into Docker

I created a new .NET Core Console Application with Visual Studio 2017 (RTM). 我使用Visual Studio 2017(RTM)创建了一个新的.NET Core Console应用程序。 Then added Docker support and got the docker file + compose files just fine. 然后添加了Docker支持并获得了docker文件+ compose文件就好了。 However there are few issues with them. 然而,它们几乎没有问题。

Docker compose files have version 2 which makes the build fail to the following error message Docker撰写文件具有版本2,这使得构建失败到以下错误消息

Microsoft.DotNet.Docker.CommandLineClientException: client version 1.22 is too old. Microsoft.DotNet.Docker.CommandLineClientException:客户端版本1.22太旧了。 Minimum supported API version is 1.24, please upgrade your client to a newer version. 支持的最低API版本为1.24,请将您的客户端升级到更新版本。

This can be fixed by manually changing the compose file versions to 2.1. 这可以通过手动将撰写文件版本更改为2.1来解决。 (not sure if valid fix) Then you'll get another error message (不确定是否有效修复)然后你会收到另一条错误消息

MSB4006 There is a circular dependency in the target dependency graph involving target "DockerCleanServiceReferences". MSB4006目标依赖关系图中存在循环依赖关系,涉及目标“DockerCleanServiceReferences”。

This I have no idea how to fix. 这我不知道如何解决。 I know the error message is due to some configuration that causes circular reference (eg post build event that does build) 我知道错误消息是由于某些配置导致循环引用(例如,构建后的构建事件)

So, any resources or tips how to package the .NET Core console application into docker container manually? 那么,如何手动将.NET Core控制台应用程序打包到docker容器中的任何资源或技巧? I'm just getting to know Docker so don't assume I know anything of it yet. 我刚刚开始了解Docker,所以不要以为我对此一无所知。

Another question, that is there some place where I could get updated versions of these Visual Studio templates or are these known issues? 另一个问题是,在某些地方我可以获得这些Visual Studio模板的更新版本,还是这些已知问题?

Can you please check if your Docker for Windows is targeting Linux? 你能否检查你的Docker for Windows是否针对Linux? It's likely you were targeting Windows container, which is not supported with .NET Core yet. 您可能是针对Windows容器,但.NET Core尚不支持。

It turned out the problem for me was having my DockerFile, SLN file, and CSPROJ file all in the same folder. 事实证明,问题在于我的DockerFile,SLN文件和CSPROJ文件都在同一个文件夹中。 You know how when you create a solution, it asks you if you want to create a subdirectory? 您知道在创建解决方案时,它会询问您是否要创建子目录吗? If you do not , and your SLN and CSPROJ files share the same folder, inevitably the Docker files will be added to this same folder, creating the circular reference. 如果不这样做 ,并且您的SLN和CSPROJ文件共享同一文件夹,则不可避免地会将Docker文件添加到同一文件夹中,从而创建循环引用。 If your SLN file lives in the directory above your CSPROJ file, the DockerFile et al will be put into your parent directory with the SLN file, and all will be well. 如果您的SLN文件位于CSPROJ文件上方的目录中,则DockerFile等将使用SLN文件放入您的父目录,并且一切都会正常。 This solved it for me. 这解决了我。

On my first spin of VS2017 with docker, using the default template, I ran in to the same issue. 在我第一次使用docker旋转VS2017时,使用默认模板,我遇到了同样的问题。 I referred to this article - https://blogs.msdn.microsoft.com/containerstuff/2017/03/13/visual-studio-2017-client-version-1-22-is-too-old/ This is what worked for me - As recommended, made this changes in docker-compose project's docker-compose.ci.build.yml : The 'version' parameter on the top of the file which was set to 2 , was change to 2.1 Repeated the same changes on the other files in the project including: 我参考了这篇文章 - https://blogs.msdn.microsoft.com/containerstuff/2017/03/13/visual-studio-2017-client-version-1-22-is-too-old/这是有用的对我来说 - 按照建议,在docker-compose项目的docker-compose.ci.build.yml中进行了这项更改:文件顶部的'version'参数设置为2 ,更改为2.1重复相同的更改项目中的其他文件包括:

docker-compose.yml 泊坞窗,compose.yml

docker-compose.override.yml 泊坞窗,compose.override.yml

docker-compose.vs.debug.yml 泊坞窗,compose.vs.debug.yml

docker-compose.vs.release.yml 泊坞窗,compose.vs.release.yml

Regarding your question on how to package a .NET Core console application into a Docker image manually. 关于如何手动将.NET Core控制台应用程序打包到Docker镜像中的问题。 The https://github.com/dotnet/dotnet-docker-samples are intended to answer that very question. https://github.com/dotnet/dotnet-docker-samples旨在回答这个问题。 Check them out. 去看一下。 If you run into issues with them or have suggestions please log an issue ( https://github.com/dotnet/dotnet-docker-samples/issues ). 如果您遇到问题或有建议请记录一个问题( https://github.com/dotnet/dotnet-docker-samples/issues )。

Thanks for the post. 谢谢你的帖子。 We will be adding Nano Server container tooling "soon". 我们将“尽快”添加Nano Server容器工具。 Until then, you can work with Linux containers which will give a similar experience. 在此之前,您可以使用Linux容器,这将提供类似的体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker如何构建.Net核心应用? - How to build .Net core application in Docker? 控制docker中托管的.NET Core控制台应用程序的生命周期 - Control lifetime of .NET Core console application hosted in docker 访问由 Docker 内的 .NET Core Console Application 生成的日志文件 - Access a log file generated by .NET Core Console Application inside Docker Docker 容器中的 .net Core Console 应用程序抛出 System.ObjectDisposedException - .net Core Console application in Docker Container throws System.ObjectDisposedException 如何使用 docker 在 Jenkins 中构建 .net 核心应用程序并将其推送到 ECR? - How to build .net core application in Jenkins using docker and push it to ECR? 即使在 .NET Core 控制台应用程序中使用 Console.ReadLine() docker 容器也会立即退出 - docker container exits immediately even with Console.ReadLine() in a .NET Core console application 应用程序日志记录 .net core 和 docker - Application logging .net core & docker .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container 将命令行参数传递给Visual Studio容器工具中.NET Core控制台应用程序的Docker调试运行 - Pass command line args to a Docker debugging run of a .NET Core console application in Visual Studio Container Tools .net 核心 - 使用 docker compose 构建错误 - .net core - build error with docker compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM