1

我有一个 Dockerfile 构建应用程序并将其发布到这样的容器

FROM mcr.microsoft.com/dotnet/sdk:5.0 as builder
COPY . ./
RUN dotnet publish Project -c Release -o ./publish

FROM mcr.microsoft.com/dotnet/runtime:5.0 as runner
COPY --from=builder  /publish .
WORKDIR data
ENTRYPOINT ["dotnet", "../Project.dll"]

构建映像和运行容器在 Windows 上工作,但在 Ubuntu 服务器上不工作。

project_1  | Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly '/Project.dll'. The system cannot find the file specified.
project_1  |
project_1  | File name: '/Project.dll'

我认为问题在于为dotnetas指定参数../Project.dll,因为 shell 将其扩展为/Project.dlldotnet 不理解 Linux 路径。有没有办法来解决这个问题?

我是 Docker 的初学者,也许我遗漏了一些东西(Docker 不应该在每个平台上都一样吗?)

编辑:dotnet Project.dll在父目录内的容器中从 bash 运行会产生相同的输出

4

1 回答 1

1

原来是权限问题,而且应用程序必须在子文件夹中(而不是在根文件夹中),见https://docs.docker.com/engine/examples/dotnetcore/

FROM mcr.microsoft.com/dotnet/sdk:5.0 as builder
WORKDIR /app
COPY . ./
RUN dotnet publish Project -c Release -o ./publish

FROM mcr.microsoft.com/dotnet/runtime:5.0 as runner
WORKDIR /app
COPY --from=builder  /app/publish .
WORKDIR /app/data
CMD ../Project
于 2021-02-28T16:13:38.247 回答