Reputation: 421
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.
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?
Upvotes: 11
Views: 9557
Reputation: 4134
Got it working for asp.net core .net8.0 for arm64:
...
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS base
...
# This stage is used to build the service project
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:8.0 AS build
Note:
--platform flag should not use constant value "linux/arm64", but --platform=$BUILDPLATFORM did build amd64...
Upvotes: 0
Reputation: 39
Checkout this page for different docker image tags for dotnet https://hub.docker.com/_/microsoft-dotnet-sdk/
I just trying one of the ones in the arm32 section, because I couldn't get dotnet restore to run (even when there were no dependencies to restore).
Upvotes: 0
Reputation: 421
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
Upvotes: 17