[Bug]: Container Build on M1 Mac fails with platform error.
What happened?
When following this doc:
https://github.com/Azure/data-api-builder/blob/main/docs/running-using-a-container.md
I get the following error:
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use. ERRO[0130] error waiting for container: context canceled
Version
Microsoft.DataApiBuilder 0.5.34
What database are you using?
PostgreSQL
What hosting model are you using?
Custom Docker host
Which API approach are you accessing DAB through?
REST
Relevant log output
joey@Joeys-MacBook-Pro samples % docker run -it -v dab-config.json:/App/dab-config.json -p 5000:5000 mcr.microsoft.com/azure-databases/data-api-builder:latest --ConfigFileName dab-config.json
Unable to find image 'mcr.microsoft.com/azure-databases/data-api-builder:latest' locally
75f1877b20af: Download complete
26b72a0d9ae9: Download complete
9ab259e76745: Download complete
144ef4f6c4b8: Download complete
08c6d9bfa585: Download complete
3f9582a2cbe7: Download complete
80b88e0117ce: Download complete
2d43258c565c: Download complete
**WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested**
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use.
ERRO[0130] error waiting for container: context canceled
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Looks like we've only build the container image for linux/amd64 which is backed up by https://github.com/Azure/data-api-builder/blob/main/.pipelines/build-pipelines.yml#L269-L310
We'll need to add a --platform flag to the task that generates linux/amd64 and linux/arm64, although I'm not sure how to do that with https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/docker-v2?view=azure-pipelines&tabs=yaml
Oh, looks like the task doesn't natively support it, nor has there been much traction to get it supported - https://github.com/microsoft/azure-pipelines-tasks/issues/16491
Might have to fall back to using scripts within the pipeline to call Docker directly.
https://github.com/Azure/data-api-builder/blob/main/Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
WORKDIR /src
COPY [".", "./"]
RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as runtime
COPY --from=build /out /App
WORKDIR /App
ENV ASPNETCORE_URLS=http://+:5000
ENTRYPOINT ["dotnet", "Azure.DataApiBuilder.Service.dll"]
Needs
RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-arm64
Otherwise: WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested 9ca10b1e8ad7c52c34b2db380ce24dacb73cb93518230475aa5a4a1c26ed67ff
Related:
- https://learn.microsoft.com/en-us/dotnet/iot/deployment
- https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/cross-building.md#macos-cross-building
Hi @JerryNixon,
Given the previous updates rolled out to Docker Desktop for macOS, this recommendation I gave you a few months back might not be needed anymore:
Needs:
RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-arm64Otherwise:
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8), and no specific platform was requested 9ca10b1e8ad7c52c34b2db380ce24dacb73cb93518230475aa5a4a1c26ed67ff
The work around is simple, just two steps:
- Enable the
Rosetta for x86/amd64 emulation on Apple Siliconoption in Docker Desktop for macOS (+13.0) - Run the container using the
--platform linux/amd64option, as follows:
docker run \
--name DAB-Library \
--volume "./DAB-Config:/App/configs" \
--publish 5001:5000 \
--env-file "./DAB-Config/.env" \
--network library-network \
--platform linux/amd64 \
--detach mcr.microsoft.com/azure-databases/data-api-builder:latest \
--ConfigFileName /App/configs/dab-config.json
Let me know if you have any questions.