Home:ALL Converter>Multiple dotnet core versions on Linux Docker image

Multiple dotnet core versions on Linux Docker image

Ask Time:2019-03-06T08:58:46         Author:Varun

Json Formatter

How can I run and install multiple versions of the dotnet core framework (say 2.1 and 1.1) in a docker container on Linux?

Below is my current dockerfile and I want to add dotnet 1.1 to it as well.

FROM microsoft/dotnet:2.1.403-sdk-bionic

ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true
ENV DOTNET_CLI_TELEMETRY_OPTOUT true

RUN apt-get update && \
    apt-get install -y zip  

Author:Varun,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55013915/multiple-dotnet-core-versions-on-linux-docker-image
Pang :

You can simply copy the runtime from each image.\nFor example, use this Dockerfile to have .NET 5.0 + .NET Core 3.1 + .NET Core 2.1 + ASP.NET runtime:\n# Start with .NET Core 2.1 runtime.\nFROM mcr.microsoft.com/dotnet/core/aspnet:2.1\n\n# Add .NET Core 3.1 runtime.\nCOPY --from=mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim /usr/share/dotnet /usr/share/dotnet\n\n# Add .NET 5.0 runtime.\nCOPY --from=mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim /usr/share/dotnet /usr/share/dotnet\n\nBuild and run:\n$ docker build -t my-image . && docker run --entrypoint dotnet my-image --list-runtimes\n#1 [internal] load build definition from Dockerfile\n\n... omitted for brevity ...\n\n#4 [stage-0 1/3] FROM mcr.microsoft.com/dotnet/core/aspnet:2.1\n#4 sha256:7d63f34a82584570b0e746ac940d81e903407f58f85148263fc25428d5437fa8\n#4 DONE 0.0s\n\n#6 [stage-0 2/3] COPY --from=mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim /usr/share/dotnet /usr/share/dotnet\n#6 sha256:cddc840a53b9711f017ed9e285efd2d27cfc0216fc1c2fb5f2383a2f52fbf735\n#6 CACHED\n\n#8 [stage-0 3/3] COPY --from=mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim /usr/share/dotnet /usr/share/dotnet\n#8 sha256:d34576b2af16f150960c3b5a974d34bf97568dbc42899e359bb1bac6dc584307\n#8 CACHED\n\n#9 exporting to image\n#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00\n#9 exporting layers done\n#9 writing image sha256:61c1518c7fb1bffff0ca77410e2a5be5febae9669fb6dc695edb053190ad98c3 done\n#9 naming to docker.io/library/my-image done\n#9 DONE 0.0s\n\nUse 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them\nMicrosoft.AspNetCore.All 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]\nMicrosoft.AspNetCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]\nMicrosoft.AspNetCore.App 3.1.18 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]\nMicrosoft.AspNetCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]\nMicrosoft.NETCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App]\nMicrosoft.NETCore.App 3.1.18 [/usr/share/dotnet/shared/Microsoft.NETCore.App]\nMicrosoft.NETCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]\n",
2020-12-29T00:52:23
yy