Docker Community Forums

Share and learn in the Docker community.

Multiple asp.net core versions in single docker

For now I have asp. net 3.1.8 in my docker(my first project works on it). I add second project with diffrent version, its asp. net 2.1.0, its not possible for me to change it from project side. When I use some function from last added project I got this error:

The framework 'Microsoft.NETCore.App', version '2.1.0' was not found.
  - The following frameworks were found:
      3.1.8 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Its possible to add second version asp.net 2.1.0 to docker?

This is hierarchy in my docker container. I want to add version 2.1.0 here:

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base

WORKDIR /app
EXPOSE 44399 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Project1.Api/Project1.Api.csproj", "Project1.Api/"]
COPY ["Project2.Test/Project2.Test.csproj", "Project1.Test/"]
RUN dotnet restore "Project1.Api/Project1.Api.csproj"
COPY . .
WORKDIR "/src/Project1.Api"
RUN dotnet build "Project1.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Project1.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
ENV ASPNETCORE_URLS http://*:44399
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project1.Api.dll"]

Here is an example of multiple dotnet core framework.

FROM microsoft/dotnet:2.2-runtime-deps-stretch-slim

RUN apt-get update
&& apt-get install -y --no-install-recommends
curl
wget
gpg
apt-transport-https
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update

Install .NET Core Runtime v1.1.2

ENV DOTNET_VERSION 1.1.2
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/release/1.1.0/Binaries/$DOTNET_VERSION/dotnet-debian-x64.$DOTNET_VERSION.tar.gz

RUN curl -SL $DOTNET_DOWNLOAD_URL --output dotnet.tar.gz
&& mkdir -p /usr/share/dotnet
&& tar -zxf dotnet.tar.gz -C /usr/share/dotnet
&& rm dotnet.tar.gz
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

Install ASP.NET Core

ENV ASPNETCORE_VERSION 2.2.1
RUN curl -SL --output aspnetcore.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/$ASPNETCORE_VERSION/aspnetcore-runtime-$ASPNETCORE_VERSION-linux-x64.tar.gz
&& aspnetcore_sha512=‘e027a5dada5d139a44675f28090f996375e49fbd72f7897aa925e48803632d5bf187d4f22dc8225505ac33e6a7a05dcdd8ed19d8b6d5e46b22e628315cf13e3e’
&& echo “$aspnetcore_sha512 aspnetcore.tar.gz” | sha512sum -c -
&& mkdir -p /usr/share/dotnet
&& tar -zxf aspnetcore.tar.gz -C /usr/share/dotnet
&& rm aspnetcore.tar.gz
&& ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet
And here is the result from within the instance

root@cb87fda4dfc7:/# dotnet --info

Host (useful for support):
Version: 2.2.1
Commit: 878dd11e62

.NET Core SDKs installed:
No SDKs were found.

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Your code works well, but its not working in my dockerfile.
I think this line override all installed version from your code.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
Because its still only one available version