Docker容器问题在Macbook上构建DotNet 5 Dockerfile

dauxcl2d  于 2022-10-23  发布在  Docker
关注(0)|答案(1)|浏览(297)

我的工作有一个用DotNet5编写的API。技术团队已经切换到所有苹果产品,现在我们正在为几个Docker文件而苦苦挣扎。我们非常肯定这与我们使用M2芯片的笔记本电脑有关,而DotNet5被弃用,只在特定的架构中可用。
原始的dockerfile命令:

  1. FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine3.12 AS build-env
  2. WORKDIR /app
  3. # Copy csproj and restore as distinct layers
  4. COPY Api.sln ./
  5. COPY Source/Common/*.csproj ./Source/Common/
  6. COPY Source/Integration/*.csproj ./Source/Integration/
  7. COPY Source/Models/*.csproj ./Source/Models/
  8. COPY Source/Data/*.csproj ./Source/Data/
  9. COPY Source/BusinessLogic/*.csproj ./Source/BusinessLogic/
  10. COPY Source/Api/*.csproj ./Source/Api/
  11. RUN dotnet restore Source/Common/*.csproj
  12. RUN dotnet restore Source/Integration/*.csproj
  13. RUN dotnet restore Source/Models/*.csproj
  14. RUN dotnet restore Source/Data/*.csproj
  15. RUN dotnet restore Source/BusinessLogic/*.csproj
  16. RUN dotnet restore Source/Api/*.csproj
  17. # Copy everything else and build
  18. WORKDIR /app/Source/Common
  19. COPY ./Source/Common ./
  20. RUN dotnet build -c Release -o /app/out
  21. WORKDIR /app/Source/Integration
  22. COPY ./Source/Integration ./
  23. RUN dotnet build -c Release -o /app/out
  24. WORKDIR /app/Source/Models
  25. COPY ./Source/Models ./
  26. RUN dotnet build -c Release -o /app/out
  27. WORKDIR /app/Source/Data
  28. COPY ./Source/Data ./
  29. RUN dotnet build -c Release -o /app/out
  30. WORKDIR /app/Source/BusinessLogic
  31. COPY ./Source/BusinessLogic ./
  32. RUN dotnet build -c Release -o /app/out
  33. WORKDIR /app/Source/Api
  34. COPY ./Source/Api ./
  35. RUN dotnet build -c Release -o /app/out
  36. RUN dotnet publish -c Release -o /app/out
  37. # Build runtime image
  38. FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine3.12
  39. WORKDIR /app
  40. COPY --from=build-env /app/out .
  41. RUN apk add --no-cache icu-libs
  42. ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
  43. ENV ASPNETCORE_ENVIRONMENT=Production
  44. ARG RELEASE
  45. ENV Sentry__Release=${RELEASE}
  46. EXPOSE 80
  47. ENTRYPOINT ["dotnet", "Api.dll"]

docker-compose up在生成之前意外失败。
我们可以使用其他镜像来构建,例如mcr.microsoft.com/dotnet/sdk:6.0-alpinemcr.microsoft.com/dotnet/aspnet:6.0-alpine
但是,当启动容器时,docker返回以下错误

  1. You must install or update .NET to run this application.
  2. App: /app/Api.dll
  3. Architecture: arm64
  4. Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (arm64)
  5. .NET location: /usr/share/dotnet/
  6. The following frameworks were found:
  7. 6.0.10 at [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  8. Learn about framework resolution:
  9. https://aka.ms/dotnet/app-launch-failed
  10. To install missing framework, download:
  11. https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=arm64&rid=alpine.3.16-arm64

我已经尝试了DotNet上可用的大多数其他与Dotnet相关的图片。昨天的大部分时间都在尝试https://hub.docker.com/_/microsoft-dotnet-sdk/的AMD64和/或arm64图像的组合
另一个开发人员希望通过API并手动将所有内容迁移到DotNet6。
我在dockerfile中尝试了--roll-forward Major命令的不同变体,但只尝试在运行时映像上实现它。是否可以在dockerfile中前滚每个单独的项目版本?
我们都是码头世界的新手,我对DotNet知之甚少。有没有办法自动迁移到DotNet 6?是否有其他坞站映像已经解决了此问题?

gstyhher

gstyhher1#

Apple Silicon Support是在.NET6中引入的,因此您需要将您的项目/解决方案更新到该主要版本。微软有一个.NET 5 to 6 migration guide可以让你开始过渡。

相关问题