You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04下构建Example Voting App Worker镜像报错求助

解决Example Voting App Worker镜像构建的两类错误

错误1:Platform解析错误

failed to parse platform : “” is an invalid component of “”: platform specifier component must match"^[A-Za-z0-9_-]+$": invalid argument

  • 原因:官方Dockerfile中FROM指令的platform参数格式不兼容你的Docker版本,或者BUILDPLATFORM变量未正确传递/解析。
  • 修复步骤:
    1. 修改Dockerfile的FROM行:移除--platform=$BUILDPLATFORM参数,比如将FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime:6.0改为FROM mcr.microsoft.com/dotnet/runtime:6.0。若需指定平台,直接写具体值,如FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/runtime:6.0。
    2. 升级Docker版本(Ubuntu 20.04自带版本偏旧):
      sudo apt purge docker docker-engine docker.io containerd runc
      sudo apt update
      sudo apt install ca-certificates curl gnupg lsb-release
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
      echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
      sudo apt update
      sudo apt install docker-ce docker-ce-cli containerd.io
      

错误2:COPY文件找不到错误

COPY failed: file not found in build context or excluded by .dockerignore: stat src/Worker/Worker.csproj: file does not exist

  • 原因:构建上下文路径错误、项目目录结构与Dockerfile路径不匹配,或文件被.dockerignore排除。
  • 修复步骤:
    1. 确认构建命令执行路径:必须在Example Voting App的项目根目录下执行docker build . -t worker,该目录需包含src/Worker/Worker.csproj路径。
    2. 核对路径一致性:检查Dockerfile中的COPY指令路径(如COPY src/Worker/Worker.csproj src/Worker/)与本地实际文件路径是否一致,若本地Worker项目路径不同,修改Dockerfile中的路径为实际路径。
    3. 检查.dockerignore:查看当前目录下的.dockerignore文件,确保未添加src/或Worker.csproj的排除规则,若有则删除对应规则。

内容的提问来源于stack exchange,提问作者ahens000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 13:25:18