Docker 发布Dotnet Core 镜像,提示Did you mean to run dotnet SDK commands解决方案

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["SampleTest.csproj", "./"]
RUN dotnet restore "./SampleTest.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "SampleTest.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SampleTest.csproj" -c Release -o /app/out
FROM base AS finalWORKDIR /app
COPY --from=publish /app/out .  //工作目录应该需要填写这个,映射失败将会提示上面的提示
ENTRYPOINT ["dotnet", "SampleTest.dll"]

docker run -it -p 8000:80 --name test01 -v e:\docker:/app/out xxxx

如果使用 -v e:\docker:/app则找不到目录,因此提示
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

另外,据测试。如果目录写为根目录/app,那么在映射目录时,无法复制到文件.我暂时只发现在/app/out(什么目录都可以)下正常使用-v
在程序里面的路径,比如使用File.WriteAllText("/app/out/这里输出正常.txt"),需要这样写才能在E:\docker找得到 “这里输出正常.txt” 文件

你可能感兴趣的:(DotnetCore,C#)