由于相对路径,Docker 容器中的 运行 dotnet 在 Linux 上失败
Running dotnet in a Docker container fails on Linux because of relative path
我有一个 Docker 文件可以构建应用程序并将其发布到这样的容器中
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'
我认为问题在于将 dotnet
的参数指定为 ../Project.dll
,因为 shell 将其扩展为 /Project.dll
而 dotnet 不理解 Linux 路径。有办法解决这个问题吗?
我是 Docker 的初学者,也许我遗漏了一些东西(Docker 不应该在每个平台上都一样吗?)
编辑:运行 dotnet Project.dll
来自父目录内容器中的 bash 产生完全相同的输出
原来是权限问题,应用必须在子文件夹下(不是在根文件夹下),见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
我有一个 Docker 文件可以构建应用程序并将其发布到这样的容器中
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'
我认为问题在于将 dotnet
的参数指定为 ../Project.dll
,因为 shell 将其扩展为 /Project.dll
而 dotnet 不理解 Linux 路径。有办法解决这个问题吗?
我是 Docker 的初学者,也许我遗漏了一些东西(Docker 不应该在每个平台上都一样吗?)
编辑:运行 dotnet Project.dll
来自父目录内容器中的 bash 产生完全相同的输出
原来是权限问题,应用必须在子文件夹下(不是在根文件夹下),见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