简体   繁体   English

将 Asp.net 核心 Docker 目标从 Windows 更改为 Linux

[英]Changing Asp.net core Docker target from Windows to Linux

I have created a new ASP.net application by Visual Studio 2019. When I was creating the project, I ticked the Docker Support checkbox and selected Windows for my docker.我通过 Visual Studio 2019 创建了一个新的 ASP.net 应用程序。在创建项目时,我勾选了 Docker Support 复选框并为我的 docker 选择了 Windows。 After a while, I decided to change my docker from Windows to Linux as I have some other software on Linux container and every time I need to switch.一段时间后,我决定将我的 docker 从 Windows 更改为 Linux,因为我在 Linux 容器上有一些其他软件,并且每次需要切换时。 I did some research and I found out if I change the server URL inside the DockerFile, I can change it to Linux.我做了一些研究,发现如果我更改 DockerFile 中的服务器 URL,我可以将其更改为 Linux。 By doing it I encounter this error: Your Docker server host is configured for 'Linux', however the project targets 'Windows'通过这样做,我遇到了这个错误:您的 Docker 服务器主机配置为“Linux”,但是该项目的目标是“Windows”

Then I opened the Cs proj file and change the windows to Linux and now I see: Unable to copy file obj\\debug\\netcoreapp2.1\\xxxx.dll to bin\\debug\\netcoreapp2.1\\xxxx.dll.然后我打开 Cs proj 文件并将 Windows 更改为 Linux,现在我看到:无法将文件 obj\\debug\\netcoreapp2.1\\xxxx.dll 复制到 bin\\debug\\netcoreapp2.1\\xxxx.dll。 Access to the path bin\\debug\\netcoreapp2.1\\xxxx.dll is denied.对路径 bin\\debug\\netcoreapp2.1\\xxxx.dll 的访问被拒绝。

I reverted the change but I still see the same error.我恢复了更改,但仍然看到相同的错误。

在记事本++之类的文本编辑器中编辑您的 .csproj 文件,您应该会看到 DockerDefaultTargetOS 标记,它应该会读取 Windows 将其更改为 Linux

  • update your dockerfile, replace the base instruction by this line "FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base"更新您的 dockerfile,用这一行替换基本指令“FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base”
  • do the same with build instruction: FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build对构建指令执行相同操作:FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
  • update your csproj tag DockerDefaultTargetOS to point to linux更新您的 csproj 标签 DockerDefaultTargetOS 以指向 linux

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

相关问题 如何在Windows的Docker linux容器中从ASP.NET Core公开端口? - How can I expose a port from ASP.NET Core in Docker linux container in Windows? Linux 中的主机 ASP.NET 内核与 Apache ZC5FD214CDD0D2B3B4272E73B022BA5 - Host ASP.NET Core in Linux with Apache Docker 如何将Windows Identity从Angle App传递到Linux服务器上托管的ASP.NET Core 2.0 WebAPI - How to pass windows Identity from angular app to asp.net core 2.0 webapi hosted on Linux server 如何从Windows向Linux机器发布.Net核心docker应用程序? - How to publish .Net core docker application from Windows to Linux machine? 从 ASP.NET Core 3 应用程序执行 Linux Shell 命令 - Exectute a Linux Shell command from ASP.NET Core 3 app 将 ASP.NET Core 从 Visual Studio 发布到 Linux - Publish ASP.NET Core from Visual Studio to Linux Docker Linux-无法使用docker exec(ASP.NET Core)进入某些目录 - Docker linux - can't cd into some directories with docker exec (ASP.NET Core) 我可以在Docker中运行现有的ASP.NET MVC应用程序而无需在Linux中转换为ASP.NET Core - Can I run existing ASP.NET MVC application in Docker without converting to ASP.NET Core in Linux 主机 ASP.NET 核心在 Linux 和 Nginx - Host ASP.NET Core on Linux with Nginx ASP.NET Core 3:无法在 linux 上运行 - ASP.NET Core 3: cannot run on linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM