Dotnet restore never completes on M1 Mac when targeting linux/amd64 platform

I have an M1 macbook running Docker Desktop 4.14.1.

I have created a dot net website project. When I build my image for arm64 everything works fine. When I try to build for amd64 the build gets hung up on the dotnet restore command.

I have tried building using both the normal docker build and also docker buildx build. The buildx build gives other errors that I can’t seem to resolve either, so I decided to post here and focus on the dotnet restore hanging up to see if there is a solution to that without using buildx. If there is not then I will start a new thread to ask about the buildx errors.

Here is my dockerfile:

#See to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM AS base

FROM AS build
COPY ["MyApp.Server/MyApp.Server.csproj", "MyApp.Server/"]
COPY ["MyApp/MyApp.csproj", "MyApp/"]
COPY ["MyApp.Api.User/MyApp.Api.User.csproj", "MyApp.Api.User/"]
COPY ["MyApp.Api.Models/MyApp.Api.Models.csproj", "MyApp.Api.Models/"]
COPY ["MyApp.Configuration/MyApp.Configuration.csproj", "MyApp.Configuration/"]
COPY ["MyApp.User.Services/MyApp.User.Services.csproj", "MyApp.User.Services/"]
COPY ["MyApp.Api.Data/MyApp.Api.Data.csproj", "MyApp.Api.Data/"]
COPY ["MyApp.User/MyApp.User.csproj", "MyApp.User/"]
RUN dotnet restore "MyApp.Server/MyApp.Server.csproj"
COPY . .
WORKDIR "/src/MyApp.Server"
RUN dotnet build "MyApp.Server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyApp.Server.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

Here is my command line I am using to build for amd64:

docker build -f MyApp.Server/Dockerfile --platform linux/amd64 .
--platform amd64

should be

--platform linux/amd64

Since I think it should give you an error if “amd64” was invalid, I guess Docker converts it to “linux/amd64”, but you can still try with the longer platform name.

Although I think it is more likely that the process inside the build container cannot finish. Maybe because it cannot be emulated properly. Emulation is helpful, but not a perfect solution.

I am sorry I put the wrong thing in my post. I am using linux/amd64 actually and it still does the dotnet restore hang up.

Thank you for pointing that out.

@hotshot10101 I’m seeing the same issue locally as well, doesn’t matter if i pass in through the CLI or add it to the FROM in the Dockerfile.

So far I’ve tried this on Docker Desktop version 4.14.1 (91661) and 4.15.0 (93002). Going to try some older versions. Did you manage to resolve it yet?

I have not resolved it. Still hoping someone can fix it or give a good work around.

I did find an alternative method of building, but it is a whole different way. Here is a link to a video on youtube showing the new net7 dotnet docker commands:

I am also having this problem, but only after updating to net7. Net6 was fine.

1 Like

Has anyone found a solution? I’m stuck with the same issue.

Mac M1 Pro
Docker version 20.10.21, build baeda1f

Hey all,

I finally got it to work thanks to this → Segmentation fault building project on dotnet/sdk:7.0 image with Apple M1 · Issue #4225 · dotnet/dotnet-docker · GitHub

I removed --platform=linux/amd64 from my powershell script
docker buildx build -t blah/meh --force-rm -f abc/Dockerfile .

and forced the runtime in my dockerfile such as
FROM AS base


Thank you guy, it is really work.
It took me 2 days to solve.

One year later and I just wanted to say thank you for this answer! Unsung heros like you keep the community going.

You’re a genius :pray:
So restore & build with

FROM AS build

then, create runtime with

FROM AS runtime


docker buildx build --force-rm -t $(IMAGE_NAME) .

I have this same problem and I cannot get it to work.

I have:

FROM AS base
FROM AS build

in my dockerfile, and am building with

docker buildx build --push --force-rm -t mytag .

…yet when I pull the image on the Linux AMD box, I get:

no matching manifest for linux/amd64 in the manifest list entries

What gives?