Search code examples
c#.netdockerlinux-containers

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


I have used Visual Studio 2017 (on Windows) to create my .Net Core App and am trying to run it inside a docker container. Based on their website .NET Core Apps should allow us developers to create cross-platform compatible software;

.NET Core is a cross-platform version of .NET for building websites, services, and console apps.

My attempt on that was to create a .NET Core Console Application;

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!");
        }
    }
}

Publish it via dotnet publish and run it by the following;

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

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

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

.. however I do always seem to get the following error-message;

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

.. which I interpret as "You should use Windows-container to run this". But now I am confused since both my console application and my container should both be cross-platform compatible, right? Or am I missing something?


Solution

  • The line:

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

    is loading a microsoft nanoserver 2016 as base image. THis is a windows server, not a linus server. OBVIOUSLY the resulting image must run on a WIndows Kernel.

    Use a Linux base image if you want a Linux base image.

    There are two relevant links:

    There simply is no way to make the platform apltform independent. As docker does not run a VM but "slim" virtualization sharing the main OS.... the main OS of the image MUST match.