RUN dotnet restore - Error on Mac with M2 chip

A L 50 Reputation points
2024-06-29T07:19:45.69+00:00

Hi there,

I am following the guide here: https://video2.skills-academy.com/en-nz/training/modules/intro-to-containers/5-exercise-create-custom-docker-image

I have followed the steps to prepare a Dockerfile file and then run the command: docker build -t reservationsystem .

However, I got the error:

=> CACHED [ 3/10] COPY [/HotelReservationSystem/HotelReservationSystem.c 0.0s

=> CACHED [ 4/10] COPY [/HotelReservationSystemTypes/HotelReservationSys 0.0s

=> ERROR [ 5/10] RUN dotnet restore "HotelReservationSystem/HotelReserva 1.6s


[ 5/10] RUN dotnet restore "HotelReservationSystem/HotelReservationSystem.csproj":

1.621 qemu: uncaught target signal 6 (Aborted) - core dumped

1.623 Aborted


Dockerfile:5


3 | COPY ["/HotelReservationSystem/HotelReservationSystem.csproj", "HotelReservationSystem/"]

4 | COPY ["/HotelReservationSystemTypes/HotelReservationSystemTypes.csproj", "HotelReservationSystemTypes/"]

5 | >>> RUN dotnet restore "HotelReservationSystem/HotelReservationSystem.csproj"

6 |

7 | COPY . .


ERROR: failed to solve: process "/bin/sh -c dotnet restore "HotelReservationSystem/HotelReservationSystem.csproj"" did not complete successfully: exit code: 134

Looks like some issues with dotnet restore.

I did some research and cant find a solution, thank you in advance!

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
1,218 questions
{count} votes

Accepted answer
  1. AmaranS 3,365 Reputation points Microsoft Vendor
    2024-07-01T06:20:15.0733333+00:00

    Hi A L,

    Thank you for reaching out to us on Microsoft Q&A forum. 

    The error message you are encountering (exit code: 134) typically indicates a more serious issue that could be related to the compatibility of the .NET SDK with the ARM architecture of the M2 chip, or it could be related to dependencies in your project.

    Here are some additional steps you can take to troubleshoot and resolve this issue:

    Check Compatibility: Ensure you are using a version of .NET SDK that supports ARM64 architecture. As of .NET 6, there is better support for Apple Silicon.

    Install Latest .NET SDK: Download and install the latest version of the .NET SDK from the official .NET website. Ensure you choose the ARM64 version.

    Run under Rosetta 2: If you have installed the x64 version of .NET SDK, you might need to run your terminal under Rosetta 2.

    • Right-click on the Terminal app in Finder.
      • Select "Get Info".
      • Check the "Open using Rosetta" option.
      Then, try running dotnet restore again in this terminal. Docker Settings: Ensure your Docker settings are correctly configured to use the right platform architecture.
      - Go to Docker Desktop preferences.
      
         - Under "Features in development", enable "Use Rosetta for x86/amd64 emulation on Apple Silicon".
      
    1. Update Dockerfile: Modify your Dockerfile to ensure compatibility with the ARM64 architecture. Here's an example Dockerfile snippet:
         FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
      

    WORKDIR /source

    Copy csproj and restore as distinct layers

    COPY *.sln . COPY HotelReservationSystem/HotelReservationSystem.csproj HotelReservationSystem/ RUN dotnet restore HotelReservationSystem/HotelReservationSystem.csproj

    Copy everything else and build

    COPY . . WORKDIR /source/HotelReservationSystem RUN dotnet build --no-restore -c Release -o /app/build

    FROM build AS publish RUN dotnet publish --no-restore -c Release -o /app/publish

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "HotelReservationSystem.dll"]

       
    1. **Diagnostics**: Add diagnostics to understand the issue better. Modify your Dockerfile to include verbose logging:
    
       ```dockerfile
       FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
    WORKDIR /source
    
    COPY *.sln .
    COPY HotelReservationSystem/HotelReservationSystem.csproj HotelReservationSystem/
    RUN dotnet restore HotelReservationSystem/HotelReservationSystem.csproj -v diag
    

    Check Logs: Examine the logs for more specific error messages. The -v diag flag will provide detailed diagnostic logs that can help pinpoint the issue.

    1. Remove Docker Cache: Sometimes, cached layers in Docker can cause issues. Try building your image without cache.
         
         docker build --no-cache -t your_image_name .
      

    By following these steps, you should be able to identify and resolve the issue causing the dotnet restore command to fail on your Mac with an M2 chip. If you still face problems, providing the detailed output from the diagnostic logs can help further narrow down the cause.

    If you continue to face issues, please let us know in the comments. We are here to help.

    If you find this information helpful, please acknowledge by clicking the "Upvote" and "Accept Answer" buttons on the post.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful