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?
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
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