Docker: 运行 dotnet publish -o /output 在 CLI 上导致非零错误

Docker: Running dotnet publish -o /output results in a nonzero error on CLI

我正在使用 Ubuntu 16.04 LTS,


Docker-compose v 1.18.0-rc2, build 189468b
Docker version 17.12.0-ce-rc1, build ee2f943

运行 此命令:dotnet publish -o /output with docker 导致此错误:


ERROR: Service 'generator' failed to build: The command '/bin/sh -c 
dotnet publish -c Release -o out' returned a non-zero code: 145

我已经为 Ubuntu 安装了 .NET SDK,但不确定如何解决这个错误;它只是不会创建那个发布文件夹;这是 dotnet --info

joel@worker-2:~/workspace/asp (copy)/api$ dotnet --info .NET Command Line Tools (2.0.2)

Product Information: Version: 2.0.2 Commit SHA-1 hash: a04b4bf512

Runtime Environment: OS Name: ubuntu OS Version: 16.04 OS Platform: Linux RID: ubuntu.16.04-x64 Base Path:
/usr/share/dotnet/sdk/2.0.2/

Microsoft .NET Core Shared Framework Host

Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Link to the same question worded differently with more error logs

首先,如果您使用 Ubuntu,docker 与 Windows 无关。

我看到 dotnet publish -c Release -o out 在“Dockerize a .NET Core application" (and the repo dotnet/dotnet-docker-samples) 中使用,图像以

开头
FROM microsoft/aspnetcore-build:2.0 AS build-env

这是一个多架构的标签,这意味着它会根据主机(这里是 Ubuntu)拉取 Windows 或 Linux 容器
但是你在 previous question following the pluralsight.com course docker-images-containers-aspdotnet-core 中提到,那个可能只有在 Windows 上完成时才有效(意思是 Windows 服务器 2016/2017,能够执行 Windows 图像)

您看到的错误是因为您的项目包含一个 global.json 文件,该文件将所需的 SDK 版本固定为 2.0.2。但是,docker 图像包含较新的 SDK 版本(当前版本为 2.1.3)。因为您用来构建的 docker 映像中不存在 2.0.2 SDK,所以它只是出错。