簡體   English   中英

有什么方法可以在Linux容器中運行.NET Core App?

[英]Is there any way to run a .NET Core App inside a Linux container?

我已使用Visual Studio 2017(在Windows上)創建我的.Net Core App並嘗試在Docker容器中運行它。 在他們的網站上, .NET Core Apps應該允許我們的開發人員創建跨平台兼容的軟件;

.NET Core是.NET的跨平台版本,用於構建網站,服務和控制台應用程序。

我的嘗試是創建一個.NET Core控制台應用程序。

using System;
using Newtonsoft.Json;

namespace Services
{
    class Program
    {
        static void Main(string[] args)
        {
            if (Enum.TryParse(
                typeof(LoremIpsumGenerator.TypeOfGenerator),
                args[0],
                true,
                out var testParse))
            {
                Console.WriteLine(
                    JsonConvert.SerializeObject(
                        LoremIpsumGenerator
                            .GenerateText(
                                int.Parse(args[1]),
                                (LoremIpsumGenerator.TypeOfGenerator) testParse)));
            }

            Console.WriteLine("Wrong Parameters!");
        }
    }
}

通過dotnet publish它,並通過以下方式運行它;

FROM microsoft/aspnetcore:1.0.13-nanoserver-sac2016 AS base  

WORKDIR /Services  
COPY /bin/Debug/netcoreapp2.0/publish/ .  

ENTRYPOINT ["dotnet", "DockerConsoleTestApp.dll"]

..但是我似乎總是收到以下錯誤消息;

image operating system "windows" cannot be used on this platform

..我解釋為“您應該使用Windows容器來運行它”。 現在我因為這兩個我的控制台應用程序混亂我的容器都應該是跨平台兼容的,對不對? 還是我錯過了什么?

該行:

FROM microsoft/aspnetcore:1.0.13-nanoserver-sac2016 AS base  

正在加載Microsoft nanoserver 2016作為基本映像。 這是Windows服務器,而不是Linus服務器。 顯然,生成的圖像必須在Windows內核上運行。

如果需要Linux基本映像,請使用Linux基本映像。

有兩個相關鏈接:

根本沒有辦法使平台應用程序獨立。 由於docker不運行VM,而是共享主OS的“苗條”虛擬化...。映像的主OS必須匹配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM