7

Introduction

I'm currently trying to automate building a docker image with dotnet for multiple platforms.

I've read that the best way to do this is to make use of docker buildx command.

I tried to set this up for arm32 arm64 and x64. The builds for x64 and arm64 work fine using this command however I'm running into an issue with arm32. This is the command I'm executing:

docker buildx build -f DeveMazeGeneratorCore.Web/Dockerfile --platform linux/arm,linux/arm64,linux/amd64 -t devedse/devemazegeneratorcoreweb .

Error

The error I get is:

#17 [linux/arm/v7 build 5/8] RUN dotnet restore "DeveMazeGeneratorCore.Web/D... 

272#17 0.254 A fatal error occurred, the folder [/usr/share/dotnet/host/fxr] does not contain any version-numbered child folders 

273#17 ERROR: executor failed running [/bin/sh -c dotnet restore "DeveMazeGeneratorCore.Web/DeveMazeGeneratorCore.Web.csproj"]: exit code: 131

I've already read here (https://github.com/dotnet/dotnet-docker/issues/1537#issuecomment-615269150) that you apparently can't build arm32 images on a 64 bit system. Can someone shed some light on why this? I mean we're using QEMU to emulate arm right?

I could solve this issue by creating a new dockerfile which builds based on a 64bit image and then creates an arm32 bit image. Like this:

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

FROM mcr.microsoft.com/dotnet/core/sdk:3.1.402-buster-arm64v8 AS build
WORKDIR /src
COPY ["DeveMazeGeneratorCore.Web/DeveMazeGeneratorCore.Web.csproj", "DeveMazeGeneratorCore.Web/"]
COPY ["DeveMazeGeneratorCore/DeveMazeGeneratorCore.csproj", "DeveMazeGeneratorCore/"]
RUN dotnet restore "DeveMazeGeneratorCore.Web/DeveMazeGeneratorCore.Web.csproj"
COPY . .
WORKDIR "/src/DeveMazeGeneratorCore.Web"
RUN dotnet build "DeveMazeGeneratorCore.Web.csproj" -c Release -o /app/build

FROM build AS publish
ARG BUILD_VERSION
ARG VER=${BUILD_VERSION:-1.0.0}
RUN dotnet publish "DeveMazeGeneratorCore.Web.csproj" -c Release -o /app/publish /p:Version=$VER

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

With buildx the idea is to re-use the same dockerfile though. So is there another way to be able to do this using buildx? (E.g. conditional checks or something like that). Or is there a newer/better way of being able to solve this? I've also looked into using multiple Dockerfiles with buildx but couldn't find anything related to this.

Theoretically I could fall back to manually doing this using docker manifests and pushing them all to the same tag, but since this seems to be quite a bit of hassle and everyone suggests buildx I'd rather use that. Check out my github + github actions where I'm trying to build this: https://github.com/devedse/DeveMazeGeneratorCore

Devedse
  • 1,801
  • 1
  • 19
  • 33

0 Answers0