与docker的dotnet核心2
我正在尝试使用基于microsofts dokumentation的docker运行dotnet core 2( https://github.com/dotnet/dotnet-docker-samples/tree/master/aspnetapp ):
我的Dockerfile看起来像这样:
FROM microsoft/aspnetcore-build:2.0.0 AS build-env WORKDIR /app # copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # build runtime image FROM microsoft/aspnetcore:2.0.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "api.bauernsuche.de.dll"]
然后我通过以下方式启动图像构build过程:
docker build -t bauernsucheapi .
构build完成后,我试图通过以下方式启动新映像:
docker run -it --rm -p 5000:80 --name bauernsuche_api bauernsucheapi
预期 :容器正在运行
IS :错误消息:你的意思是运行dotnet SDK命令? 请从以下url安装dotnet SDK: http : //go.microsoft.com/fwlink/? LinkID=798306&clcid=0x409
现在,因为我使用的是微软Docker iage,所以我希望这个SDK可以使用。 此外,我的Dockerfile是一个从Microsoft示例的直接副本进行一个更改:Versionnumber从2.0更改为2.0.0,这似乎是正确的,因为2.0给了我关于找不到图像的错误。
那么我做错了什么?
我的.csproj文件:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> </PropertyGroup> <ItemGroup> <Folder Include="wwwroot\" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" /> <PackageReference Include="Moq" Version="4.7.99" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /> <PackageReference Include="xunit" Version="2.3.0-beta4-build3742" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta4-build3742" /> <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" /> </ItemGroup> </Project>
编辑:当我在这里回答:
为什么你可以看到这个错误信息的一个原因是传递给
dotnet
的参数是未知的。
runtime
无法识别您传递给它的参数,并怀疑您是否应该使用sdk
。确保dll的名称和path正确:
ENTRYPOINT ["dotnet", "api.bauernsuche.de.dll"]
此外,请确保
COPY
指令按预期工作,以便dll位于WORKDIR
位置。
原始答案:
您正在使用没有SDK的图像。
下面是一个示例,显示在图像中构build应用程序,然后创build一个新的结果:
FROM microsoft/dotnet:2.0-sdk AS build-env WORKDIR /app # copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out -r debian.8-x64 # build runtime image FROM microsoft/dotnet:2.0-runtime WORKDIR /app COPY --from=build-env /app/out ./ EXPOSE 5000/tcp ENTRYPOINT ["dotnet", "api.dll"] # To be able to pass parameters (eg: override configuration) CMD []
从这里采取。
注意第一个是sdk图像,第二个是运行时 。 正如您可以从网站下载时一样select。
所以我不确定问题是什么,但是在sh
和bash
之间切换会有所帮助。 这我主要是作为基本图像中的错误,你应该报告它。 但下面应该为你解决它
FROM microsoft/aspnetcore-build:2.0.0 AS build-env WORKDIR /app # copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # build runtime image FROM microsoft/aspnetcore:2.0.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["/bin/bash", "-lc", "dotnet api.bauernsuche.de.dll"]