【问题标题】:How to build docker container image for ARM32 architecture from Windows 10 OS?如何从 Windows 10 操作系统为 ARM32 架构构建 docker 容器映像?
【发布时间】:2019-01-05 11:48:28
【问题描述】:

我正在为我的 Raspberry Pi 3 Model B+ 开发 Asp.Net Core 应用程序(带有 React 前端)。基于模板的应用(dotnet new react -o react-app)。

我想在我的 Windows 操作系统笔记本电脑上本地开发和调试应用程序,然后为 ARM32 架构构建应用程序,将映像推送到 docker hub 并在 Raspberry 设备上拉取并运行映像。

我发现,如果我在 Windows 笔记本电脑上使用 microsoft/dotnet:2.2-sdk 和 microsoft/dotnet:2.2-aspnetcore-runtime 构建应用程序,那么我无法在 Raspberry 设备上运行此映像并显示错误消息:' standard_init_linux.go:190: exec 用户进程导致“exec 格式错误”。看起来 Windows 构建的映像仅适用于 AMD64 架构。

然后我尝试将构建器和运行时映像更改为 ARM32,但现在构建过程崩溃并出现错误:

qemu: Unsupported syscall: 389 
qemu: Unsupported syscall: 345 qemu:
uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault The command '/bin/sh -c dotnet restore' returned a
non-zero code: 139

我的 Docker 文件:

#FROM microsoft/dotnet:2.2-sdk AS builder
FROM microsoft/dotnet:2.2-sdk-stretch-arm32v7 AS builder
WORKDIR /source

RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
RUN apt-get install -y nodejs

COPY *.csproj .
RUN dotnet restore

COPY ./ ./

RUN dotnet publish "./react-app.csproj" --output "./dist" --configuration Release --no-restore

#FROM microsoft/dotnet:2.2-aspnetcore-runtime
FROM microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim-arm32v7 as runtime
WORKDIR /app
COPY --from=builder /source/dist .
EXPOSE 80
ENTRYPOINT ["dotnet", "react-app.dll"]

是否可以从 Windows 操作系统为 Raspberry 设备构建映像?

如果是,您能帮我解决一下 Docker 设置吗?

【问题讨论】:

    标签: docker .net-core raspberry-pi react-redux


    【解决方案1】:

    我对 Docker 的东西还很陌生,但是我有一个在我的 RPi 上运行的 Azure Edge 模块的示例,这应该是相同的概念。对于构建环境,我使用microsoft/dotnet:2.1-sdk - 这是因为我的主机是 Win10 x86_64 并且生成的 IL 代码无论如何都与平台无关。 但是由于目标平台是 arm32v7,所以 dotnet 运行时 必须是 arm32v7。所以对于运行时我使用microsoft/dotnet:2.1-runtime-stretch-slim-arm32v7(或microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim-arm32v7在你的情况下)。

    试试这个 Dockerfile:

    FROM microsoft/dotnet:2.2-sdk AS builder
    WORKDIR /source
    
    RUN curl -sL https://deb.nodesource.com/setup_10.x |  bash -
    RUN apt-get install -y nodejs
    
    COPY *.csproj .
    RUN dotnet restore
    
    COPY ./ ./
    
    RUN dotnet publish "./react-app.csproj" --output "./dist" --configuration Release --no-restore
    
    FROM microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim-arm32v7 as runtime
    WORKDIR /app
    COPY --from=builder /source/dist .
    EXPOSE 80
    ENTRYPOINT ["dotnet", "react-app.dll"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多