Home > Back-end >  Docker container issues building dotnet 5 Dockerfile on Macbook
Docker container issues building dotnet 5 Dockerfile on Macbook

Time:10-21

My work has a an API written in dotnet 5. The tech team has switched to all apple products and now we are struggling with a few Dockerfiles. We are pretty sure it has to do with our laptops using M2 chips, and dotnet 5 being deprecated and only being available in a specific architecture.

The original dockerfile commands:

FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.12 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY Api.sln ./
COPY Source/Common/*.csproj ./Source/Common/
COPY Source/Integration/*.csproj ./Source/Integration/
COPY Source/Models/*.csproj ./Source/Models/
COPY Source/Data/*.csproj ./Source/Data/
COPY Source/BusinessLogic/*.csproj ./Source/BusinessLogic/
COPY Source/Api/*.csproj ./Source/Api/

RUN dotnet restore Source/Common/*.csproj
RUN dotnet restore Source/Integration/*.csproj
RUN dotnet restore Source/Models/*.csproj
RUN dotnet restore Source/Data/*.csproj
RUN dotnet restore Source/BusinessLogic/*.csproj
RUN dotnet restore Source/Api/*.csproj

# Copy everything else and build
WORKDIR /app/Source/Common
COPY ./Source/Common ./
RUN dotnet build -c Release -o /app/out

WORKDIR /app/Source/Integration
COPY ./Source/Integration ./
RUN dotnet build -c Release -o /app/out

WORKDIR /app/Source/Models
COPY ./Source/Models ./
RUN dotnet build -c Release -o /app/out

WORKDIR /app/Source/Data
COPY ./Source/Data ./
RUN dotnet build -c Release -o /app/out

WORKDIR /app/Source/BusinessLogic
COPY ./Source/BusinessLogic ./
RUN dotnet build -c Release -o /app/out

WORKDIR /app/Source/Api
COPY ./Source/Api ./
RUN dotnet build -c Release -o /app/out

RUN dotnet publish -c Release -o /app/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine3.12
WORKDIR /app
COPY --from=build-env /app/out .
RUN apk add --no-cache icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
ENV ASPNETCORE_ENVIRONMENT=Production
ARG RELEASE
ENV Sentry__Release=${RELEASE}
EXPOSE 80
ENTRYPOINT ["dotnet", "Api.dll"]

docker-compose up expectedly fails before build.

We can use other images to build, such as mcr.microsoft.com/dotnet/sdk:6.0-alpine and mcr.microsoft.com/dotnet/aspnet:6.0-alpine.

But then docker returns the following error when starting the container

You must install or update .NET to run this application.

App: /app/Api.dll
Architecture: arm64
Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (arm64)
.NET location: /usr/share/dotnet/

The following frameworks were found:
  6.0.10 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=arm64&rid=alpine.3.16-arm64

I have tried most of the other images available on docker hub related to dotnet. spent most of yesterday just trying combinations of amd64 and / or arm64 images from https://hub.docker.com/_/microsoft-dotnet-sdk/

The other dev wants to go through the API and manually migrate everything to dotnet 6.

I tried different variations of the --roll-forward Major command in the dockerfile, but only tried implementing it on the runtime image. Is it possible to roll forward each individual project version in the dockerfile?

We are all rather new to the docker world, and I have very little knowledge of dotnet. Is there a way to automate the migration to dotnet 6? Is there another docker image that already addresses this problem?

CodePudding user response:

Apple Silicon support was introduced with .NET 6, so you'll need to update your project/solution to that major version. Microsoft has a .NET 5 to 6 migration guide to get you started on the transition.

  • Related