0

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?

TheRealVira
  • 1,444
  • 4
  • 16
  • 28
  • Well, you opted to use a windows server image as base image, than you'll get what you ask for. – Peter Bons Oct 24 '18 at 12:18
  • 1
    Sort of answers it. You sort of published it to windows, so it must run on windows. core has a LOT of OS you can publish it to. Why do you use a microsoft nanoserver (small windows server) as base image? – TomTom Oct 24 '18 at 12:19
  • @TomTom I have thought about using that Microsoft Nanoserver image since I currently can't think of any other slim fit base images to run my application. However I would be quite happy to hear of any alternative image! – TheRealVira Oct 24 '18 at 12:23
  • 1
    https://hub.docker.com/r/microsoft/aspnetcore/ - use a Linux image ;) The OS can per definition not be platform independent. It IS the platform. Docker is not a VM - so it MUST use the correct kernel for slim virtualization. For in depth details read https://learn.microsoft.com/en-us/dotnet/core/docker/building-net-docker-images – TomTom Oct 24 '18 at 12:34
  • Yep, I have already read your answer and marked it as accepted. Thankies. If there is any way to still edit your answer, I would appreciate an edit containing the alternatives. ( : – TheRealVira Oct 24 '18 at 12:36
  • Added references and links to the answer. You are right, you may not be the only one with this problem. – TomTom Oct 24 '18 at 12:40

1 Answers1

2

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.

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • It's not that obvious since I have got that image from "aspnetcore" and I again have thought it would be also cross-platform compatible, but sure.. I get what you are saying.. Any alternatives I could use? – TheRealVira Oct 24 '18 at 12:26
  • 1
    Actually it is. There is an official docker image (microsoft/aspnetcore) and if you bother looking at the website there is documentation. https://hub.docker.com/r/microsoft/aspnetcore/. THere are official Linux images on that place. THere is no cross platform OS image. This is not a dotnetcore issue - the image is based on a runtime, and you load a windows runtime explicily, not a linux one (which would use the 1.0.13-Jessie image for a linux base os). Your problem is that you need an OS (above dotnetcore) which can not be platform independent (as it is the platform) and you used Windows. – TomTom Oct 24 '18 at 12:32