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 asp.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 https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
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
WORKDIR /app
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.

Image: mcr.microsoft.com/dotnet/sdk:7.0
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 mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-amd64 AS base