如何在Visual Studio 2022中构建包含ASP.NET Core Web App的armv71(ARM32)Docker容器?

a1o7rhls  于 2023-05-06  发布在  Docker
关注(0)|答案(1)|浏览(142)

我正在使用Visual Studio 2022在Windows 10上工作,并试图创建一个简单的ASP.NET Core Web App(.net 7.0)并将其放入Docker映像中。这个docker镜像应该部署到armv71(ARM32)设备上(通过tar archive)。当启动“Build Docker Image”时,它会失败,并出现以下错误:

...
error CTC1014: #12 [build 4/7] RUN dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"
 : error CTC1014: #12 sha256:353b0e08e28a4e967ad5c810f36eb6453202088e54405c3c2fb3cb70be70d3bf
 : error CTC1014: #12 9.885 Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
 : error CTC1014: #12 9.888    at Regex1_Scan(RegexRunner, ReadOnlySpan`1)
 : error CTC1014: #12 9.888    at System.Text.RegularExpressions.Regex.RunAllMatchesWithCallback[TState](String inputString, ReadOnlySpan`1 inputSpan, Int32 startat, TState& state, MatchCallback`1 callback, RegexRunnerMode mode, Boolean reuseMatchObject)
 : error CTC1014: #12 9.893 qemu: uncaught target signal 6 (Aborted) - core dumped
 : error CTC1014: #12 9.921 Aborted
 : error CTC1014: #12 ERROR: executor failed running [/bin/sh -c dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"]: exit code: 134
 : error CTC1014: ------
 : error CTC1014:  > [build 4/7] RUN dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj":
 : error CTC1014: ------
 : error CTC1014: executor failed running [/bin/sh -c dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"]: exit code: 134

有时候我会这样

error CTC1014: #12 [build 4/7] RUN dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"
 : error CTC1014: #12 sha256:7b86b8130fe749ac2390d652e6070685f81fc5ba8e51ca7d8fdf198580978932
 : error CTC1014: #12 5.024 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
 : error CTC1014: #12 5.044 Segmentation fault
 : error CTC1014: #12 ERROR: executor failed running [/bin/sh -c dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"]: exit code: 139
 : error CTC1014: ------

我的停靠文件是:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0.4-jammy-arm32v7 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0.202-jammy-arm32v7 AS build
WORKDIR /src
COPY ["MyPlcDockerWebApp/MyPlcDockerWebApp.csproj", "MyPlcDockerWebApp/"]
RUN dotnet restore "MyPlcDockerWebApp/MyPlcDockerWebApp.csproj"
COPY . .
WORKDIR "/src/MyPlcDockerWebApp"
RUN dotnet build "MyPlcDockerWebApp.csproj" -c Release -o /app/build

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

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

我做错了什么?我已经尝试了不同的手臂基础图像,但它没有帮助。
在我的Windows机器上,当我使用www.example.com作为基础映像并使用www.example.com作为构建时,它工作正常(Docker容器获得构建并启动)mcr.microsoft.com/dotnet/aspnet:7.0mcr.microsoft.com/dotnet/sdk:7.0

zdwk9cvp

zdwk9cvp1#

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

最近的dotnet版本不支持QEMU:
.NET 7不支持通过QEMU运行(模拟)。例如,QEMU用于在x64上模拟Arm64容器,反之亦然。
据我所知,没有办法在仿真下运行dotnet。在你的情况下,你能在主机上构建你的ASP.NET应用程序,生成跨平台的二进制文件(包括所有的依赖项)并将它们包含到docker镜像中吗?或者你也需要在仿真下运行你的应用程序?

相关问题