DotNet构buildCLI在terminal中工作,但不在Docker构build中
这是我第一次尝试.net核心和docker。 我不知道什么是错的。
我可以在terminal运行dotnet restore
/ dotnet build
/ dotnet run
,没有任何问题。 该网站加载得很好。 所以我想给docker一个尝试(最终在云中的VM上运行)。
我运行docker build -t latest .
这导致:
Step 5 : RUN dotnet build ---> Running in e463aff85460 Project app (.NETCoreApp,Version=v1.0) will be compiled because project is not safe for incremental compilation. Use --build-profile flag for more information. Compiling app for .NETCoreApp,Version=v1.0 /app/project.json(32,58): error NU1001: The dependency Microsoft.EntityFrameworkCore.Sqlite >= 1.0.1 could not be resolved. Compilation failed. 0 Warning(s) 1 Error(s) Time elapsed 00:00:00.0174732 The command 'dotnet build' returned a non-zero code: 1
我已经尝试更改project.json中的SQLite版本没有任何运气。
NuGet回购:使用的饲料:
https://www.myget.org/F/aspnetcirelease/api/v3/index.json https://api.nuget.org/v3/index.json dotnet --version 1.0.0-preview3-003786
没有编辑到dockerfile:
FROM microsoft/dotnet:latest COPY . /app WORKDIR /app RUN ["dotnet", "restore"] RUN ["dotnet", "build"] EXPOSE 5000/tcp CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
尝试创build一个.dockerignore谷歌search后没有任何运气:
.git Dockerfile .DS_Store .gitignore README.md project.lock.json
我在最新的macOS(10.12)。
的package.json:
{ "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.AspNetCore.Routing": "1.0.1", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", "Microsoft.EntityFrameworkCore": "1.0.1", "Microsoft.EntityFrameworkCore.Design": { "version": "1.0.0-preview2-final", "type": "build" }, "Microsoft.EntityFrameworkCore.Relational": "1.0.1", "Microsoft.EntityFrameworkCore.SQLite": "1.0.1", "Microsoft.EntityFrameworkCore.Sqlite.Design": "1.0.1" }, "tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": { "System.GC.Server": true } }, "publishOptions": { "include": [ "wwwroot", "**/*.cshtml", "appsettings.json", "web.config" ] }, "scripts": { "precompile": [ "dotnet bundle" ], "prepublish": [ "bower install" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] }, "tooling": { "defaultNamespace": "MyFirstApp" } }
在尝试构builddocker容器之后输出:
Sending build context to Docker daemon 26.39 MB Step 1 : FROM microsoft/dotnet:latest ---> 96d122fe36cb Step 2 : WORKDIR /root ---> Using cache ---> 0c5317108a5b Step 3 : COPY bin/Debug/netcoreapp1.0/publish/ /root/ ---> Using cache ---> d79700fa6c36 Step 4 : ENTRYPOINT dotnet /root/MyProject.dll ---> Using cache ---> a99f30826ddd Successfully built a99f30826ddd
图像microsoft / dotnet:最新不是为构build而devise的,而仅仅是为了运行时。
将.net核心应用程序发布到Docker中的最佳方式是:
-
dotnet restore
-
dotnet publish
-
docker
docker build -t your-tag
与Dockerfile像:FROM microsoft/dotnet:latest WORKDIR /root COPY bin/Debug/netcoreapp1.0/publish/ /root/ ENTRYPOINT dotnet /root/[your-project-name].dll
其中bin / Debug / netcoreapp1.0 / publish是您真正的发布path。
如果你想在Docker中构build.net核心应用程序,请使用以下图像:
FROM microsoft/dotnet:onbuild
图像版本之间的区别在这里解释
问候
- 在Visual Studio 2017中添加Docker支持缺less
- 具有ASP.NET核心库的Docker容器
- 在Windows Server Core Docker上安装.NET Framework 3.5
- 使用Docker自定义Visual Studio运行configuration
- 如何在使用Dockerfile构build时解决错误“没有这样的文件或目录”错误
- 如何创build图像并将图像推送到docker中心
- 如何从docker容器中的bash检查.net核心dll的版本
- 在Docker容器中运行不可信的.net核心应用程序的最佳实践
- dotnet docker / bin / sh:1:[dotnet ,:找不到