Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying ASP.NET Core Docker image from x86 to ARM (Raspberry Pi) in VS2019

I've got Docker setup on a Raspberry Pi 4 and I want to deploy a ASP.NET Core 3.1 app (The Razor pages movie example app) to my Pi via Docker Hub. When I pull the image from Docker hub and try to run it, I get the error

standard_init_linux.go:211: exec user process caused "exec format error

I've built my Docker image on a Windows 10 x64 PC. When inspecting the Docker image on my Pi, I can see that the architecture is wrong

"Architecture": "amd64",

It should be possible to build a Docker image targeting ARM on a x64 machine since last year, but somehow my image is built targeting x64 instead. I've changed my Dockerfile to target linux-arm


FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["RazorMovies/RazorMovies.csproj", "RazorMovies/"]
RUN dotnet restore "RazorMovies/RazorMovies.csproj" -r linux-arm
COPY . .
WORKDIR "/src/RazorMovies"
RUN dotnet build "RazorMovies.csproj" -c Release -o /app/build -r linux-arm

FROM build AS publish
RUN dotnet publish "RazorMovies.csproj" -c Release -o /app/publish -r linux-arm

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RazorMovies.dll"]

and I've changed the target runtime-setting found in Build -> Publish in VS2019 to target linux-arm as well as shown in the image below.

Docker Puslish settings in VS 2019

I know that my Pi is capable of running ASP.NET Core apps through Docker, I've run the same app through Docker by using the example found here. That image shows the architecture as arm instead of amd64.

docker run --rm -it -p 8000:80 mcr.microsoft.com/dotnet/core/samples:aspnetapp

What am I missing for my image to be built targeting ARM instead of x64?

like image 663
Ultimadark Avatar asked Feb 10 '20 21:02

Ultimadark


1 Answers

Found the solution, I also needed to change the base from

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

to

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim-arm32v7 AS base
like image 108
Ultimadark Avatar answered Sep 19 '22 14:09

Ultimadark