dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.67k stars 1.06k forks source link

Support PublishAot for Linux Docker on Windows with Docker Desktop natively #38352

Open MichaelPeter opened 11 months ago

MichaelPeter commented 11 months ago

Right now if I have use the ASP.NET Core Aot sample (dotnet new webapiaot) and try to compile it as linux docker image for my docker desktop, I get the following error.

dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer -c Release

Cross-OS native compilation is not supported.

Non AOT Docker images can be build for linux/WSL2 on windows.

There are attepts at workarrounds for that on windows, like the [PublishAotCross] (https://github.com/MichalStrehovsky/PublishAotCross), which requires to manually install of the linux toolchain for windows which quite bothersome and timeconsuming. But which still don't support NativeAOT!

Since I am "stuck" working on Windows to develop my linux docker images, it would be importaint for me to be able to test my docker aot containers locally on WSL2 without too much setup effort in our team. Here I would wish for a native support - or at least simplification of projects like PublishAotCross - or compiling inside the WSL.

For once it feels like Windows is a second class Citizen in .NET Cloud Native/Docker Development, since NativeAot seems the future and Linux Docker containers are the standard this will soon get much more importaint for us.

Thank you for your help! I didn't see any issue regarding that feature yet.

ghost commented 11 months ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

Issue Details
Right now if I have use the ASP.NET Core Aot sample (dotnet new webapiaot) and try to compile it as linux docker image for my docker desktop, I get the following error. dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer -c Release **Cross-OS native compilation is not supported.** Non AOT Docker images can be build for linux. There are workarrounds for that on windows, like the [PublishAotCross](https://github.com/MichalStrehovsky/PublishAotCross ), which requires to manually install of the linux toolchain for windows which quite bothersome and timeconsuming. Since I am "stuck" working on Windows to develop my linux docker images, it would be importaint for me to be able to test my docker aot containers locally on WSL2 without too much setup effort in our team. Here I would wish for a native support - or at least simplification of projects like PublishAotCross - or compiling inside the WSL. Right now and in this case it for once feels like Windows as Second class Citizen in .NET Cloud Development, since NativeAot seems the future and Linux Docker containers are the standard this will soon get much more importaint. Thank you for your help! I didn't see any issue regarding that feature yet.
Author: MichaelPeter
Assignees: -
Labels: `area-NativeAOT-coreclr`
Milestone: -
Clockwork-Muse commented 11 months ago

compiling inside the WSL

Are you using devcontainers?

Basically, from Windows gives you a dev experience inside (a container hosted in) WSL. If you have the definition files, the only setup your team needs is WSL + Docker (Docker Desktop, installed as Docker CE inside WSL, or some other container host installed in WSL such as Podman). Then you dev as normal inside a Linux environment.

MichaelPeter commented 11 months ago

Thank you for the hint, think I have to investigate compiling inside wsl. Like here https://youtu.be/q4i3t5wLXtE?si=R9-o7wKa_iS1lkXg

Still would still ne nice if that would be easy or the .net cli could do that with not much additional effort.

Still as the topic states, the best thing would be if it would "just works" without additional setup, just pressing publish in visual studio or just one dotnet cli command in vs code.

Clockwork-Muse commented 11 months ago

You can do "bare" on-host development, but that means your environment ends up polluted with extra tools and dependencies.
This is less of an issue than it has been in years past, but it still crops up occasionally (usually in the context of native C/C++ builds, which suck because of poor build system/package management).

Using a devcontainer allows you to pass around the equivalent of a pre-configured developer(+ci, sometimes) machine for each project.

Still as the topic states, the best thing would be if it would "just works" without additional setup, just pressing publish in visual studio or just one dotnet cli command in vs code.

Possibly one reason why this doesn't exist is because it's way harder/~impossible to get Windows containers on Linux hosts. You can't just docker build ..., so you couldn't use a build stage to get away with this. Windows -> Linux is made easier because they hid the VM that's running Linux (if you're using WSL).

MichaelPeter commented 11 months ago

Possibly one reason why this doesn't exist is because it's way harder/~impossible to get Windows containers on Linux hosts. You can't just docker build ..., so you couldn't use a build stage to get away with this. Windows -> Linux is made easier because they hid the VM that's running Linux (if you're using WSL).

Yes but I am just talking only about the path Windows OS build->Linux Images. Since Windows Containers are much rarer I think this is so often requested feature to be able to build them on Linux/MacOS

The Production Builds happen in Azure DevOps agents anyway.

Clockwork-Muse commented 11 months ago

If the dockerfile would have a RUN command inside, such as for a build stage, that will require execution on a platform-native host (or emulator for some cases). If it only has COPY commands then you can create the images, but it means that you need whatever platform stack on your host, which can be more difficult to set up.