我有一个 C# ASP.NET Core 应用程序,我在 WSL 上使用 docker 部署该应用程序。 dockerfile 非常简单:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR ./app
EXPOSE 80
EXPOSE 443
FROM base AS final
WORKDIR ./app
COPY ./app/publish .
ENTRYPOINT ["dotnet", "DockerTest.dll"]
此“DockerTest”应用程序将尝试使用
System.Diagnostics.Process
执行以下 docker 命令:
docker run --rm otherimage args
这个 docker 命令在直接在 WSL 终端中运行时有效,所以我知道 docker 在那里并且命令是有效的。
但是,当我在 WSL 中运行此应用程序时,我得到:
[Win32Exception]: An error occurred trying to start process 'docker' with working directory '/app/app'. No such file or directory
在“DockerTest”应用程序中,我将
ProcessStartInfo
设置为:
new ProcessStartInfo("docker", "run --rm otherimage args")
我还明确将工作目录设置为
Environment.CurrentDirectory
。
我通过在代码中添加预检查来确认工作目录存在:
if (!Directory.Exists(workingDirectory)) { ...
那么如果工作目录存在并且 docker 在 WSL 中安装/可用,它认为什么不存在?
尝试下一个例子:
# Stage 1: Build the application
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM base AS final
WORKDIR /app
COPY --from=base /publish .
ENTRYPOINT ["dotnet", "DockerTest.dll"]
CMD ["npm", "start"]