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
You can simply copy the runtime from each image.
For example, use this Dockerfile to have .NET 5.0 + .NET Core 3.1 + .NET Core 2.1 + ASP.NET runtime:
# Start with .NET Core 2.1 runtime.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1
# Add .NET Core 3.1 runtime.
COPY --from=mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim /usr/share/dotnet /usr/share/dotnet
# Add .NET 5.0 runtime.
COPY --from=mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim /usr/share/dotnet /usr/share/dotnet
Build and run:
$ docker build -t my-image . && docker run --entrypoint dotnet my-image --list-runtimes
#1 [internal] load build definition from Dockerfile
... omitted for brevity ...
#4 [stage-0 1/3] FROM mcr.microsoft.com/dotnet/core/aspnet:2.1
#4 sha256:7d63f34a82584570b0e746ac940d81e903407f58f85148263fc25428d5437fa8
#4 DONE 0.0s
#6 [stage-0 2/3] COPY --from=mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim /usr/share/dotnet /usr/share/dotnet
#6 sha256:cddc840a53b9711f017ed9e285efd2d27cfc0216fc1c2fb5f2383a2f52fbf735
#6 CACHED
#8 [stage-0 3/3] COPY --from=mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim /usr/share/dotnet /usr/share/dotnet
#8 sha256:d34576b2af16f150960c3b5a974d34bf97568dbc42899e359bb1bac6dc584307
#8 CACHED
#9 exporting to image
#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#9 exporting layers done
#9 writing image sha256:61c1518c7fb1bffff0ca77410e2a5be5febae9669fb6dc695edb053190ad98c3 done
#9 naming to docker.io/library/my-image done
#9 DONE 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Microsoft.AspNetCore.All 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.18 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.18 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With