LoginSignup
32
41

More than 5 years have passed since last update.

実行環境に.NET Core ランタイムが不要なアプリをビルドする(自己完結型の展開)& Docker 上の Alpine Linux で動かす

Last updated at Posted at 2019-04-01

コマンドの確認

自己完結型(Self Containedな)ビルドをします。

dotnet publish -c Release -r <RUNTIME_IDENTIFIER> --self-contained true

ランタイムIDの一覧はこちら

自己完結型(Self-Contained)の展開のメリット

自己完結型の展開

.NET Core の配置にはフレームワーク依存の展開FDDと自己完結型の展開SCDがあります。
自己完結型の展開には .NET Coreランタイムが同梱されるため以下のメリットがあります。

  • デプロイ先に .NET Coreランタイムのインストールが不要。
  • .NET Core のバージョンを指定できる。ビルドした環境と実行対象プラットフォームの.NET Coreのバージョンが異なり動作しないといった不具合が起こらない。

ただし、アプリケーションのサイズがランタイムの分だけ大きくなります。自己完結型のアプリケーションを同じ環境に複数配置してもランタイムが共有されないためそれぞれで容量を消費します。
また、ビルド時に実行対象の環境を指定する必要があります。

dotnetコマンドのオプションの意味

dotnet publishコマンド

-c Release-c|--configuration {Debug|Release}

ビルド構成を定義します。 既定値はDebug
配置するのでリリースビルドを指定しています。

-r <RUNTIME_IDENTIFIER>-r|--runtime <RUNTIME_IDENTIFIER>

linux-x64とかwin10-x64とかosx-x64とか実行対象プラットフォームを指定します。

ランタイムIDの一覧

自己完結型のアプリケーションを実際にビルドしてみる

プロジェクトを作成

例としてテンプレートからWeb APIのプロジェクトを作成します。

$ cd <workdir>
$ dotnet new webapi -o SelfContainedApp
テンプレート "ASP.NET Core Web API" が正常に作成されました。

作成後のアクションを処理しています...
'dotnet restore' を SelfContainedApp/SelfContainedApp.csproj で実行しています...
  <workdir>/SelfContainedApp/SelfContainedApp.csproj のパッケージを復元しています...
  MSBuild ファイル <workdir>/SelfContainedApp/obj/SelfContainedApp.csproj.nuget.g.props を生成しています。
  MSBuild ファイル <workdir>/SelfContainedApp/obj/SelfContainedApp.csproj.nuget.g.targets を生成しています。
  /Users/sano/Desktop/SelfContainedApp/SelfContainedApp.csproj の復元が 1.11 sec で完了しました。

正常に復元されました。

自己完結型のアプリケーションをビルドする

例えばUbuntuに配置する場合、ランタイムIDはlinux-x64を指定します。

$ cd SelfContainedApp/
$ dotnet publish -c Release -r linux-x64 --self-contained true
.NET Core 向け Microsoft (R) Build Engine バージョン 15.9.20+g88f5fadfbe
Copyright (C) Microsoft Corporation.All rights reserved.

  <workdir>/SelfContainedApp/SelfContainedApp.csproj のパッケージを復元しています...
  MSBuild ファイル <workdir>/SelfContainedApp/obj/SelfContainedApp.csproj.nuget.g.props を生成しています。
  MSBuild ファイル <workdir>/SelfContainedApp/obj/SelfContainedApp.csproj.nuget.g.targets を生成しています。
  <workdir>/SelfContainedApp/SelfContainedApp.csproj の復元が 1.11 sec で完了しました。
  SelfContainedApp -> /<workdir>/SelfContainedApp/bin/Release/netcoreapp2.1/linux-x64/SelfContainedApp.dll
  SelfContainedApp -> <workdir>/SelfContainedApp/bin/Release/netcoreapp2.1/linux-x64/publish/

<workdir>/SelfContainedApp/bin/Release/netcoreapp2.1/osx-x64/publish/に自己完結型の展開をしたアプリケーションが発行されています。
※指定しませんでしたがdotnet publish-oオプションを指定すると展開先のディレクトリを指定できます。

$ tree bin/Release/netcoreapp2.1/linux-x64/publish/
bin/Release/netcoreapp2.1/linux-x64/publish/
├── Microsoft.AspNetCore.Antiforgery.dll
├── Microsoft.AspNetCore.Authentication.Abstractions.dll
├── Microsoft.AspNetCore.Authentication.Cookies.dll
├── Microsoft.AspNetCore.Authentication.Core.dll
├── Microsoft.AspNetCore.Authentication.Facebook.dll
├── Microsoft.AspNetCore.Authentication.Google.dll
├── Microsoft.AspNetCore.Authentication.JwtBearer.dll
├── Microsoft.AspNetCore.Authentication.MicrosoftAccount.dll
├── Microsoft.AspNetCore.Authentication.OAuth.dll
├── Microsoft.AspNetCore.Authentication.OpenIdConnect.dll
├── Microsoft.AspNetCore.Authentication.Twitter.dll
├── Microsoft.AspNetCore.Authentication.WsFederation.dll
├── Microsoft.AspNetCore.Authentication.dll
├── Microsoft.AspNetCore.Authorization.Policy.dll
├── Microsoft.AspNetCore.Authorization.dll
├── Microsoft.AspNetCore.Connections.Abstractions.dll
├── Microsoft.AspNetCore.CookiePolicy.dll
├── Microsoft.AspNetCore.Cors.dll
├── Microsoft.AspNetCore.Cryptography.Internal.dll
├── Microsoft.AspNetCore.Cryptography.KeyDerivation.dll
├── Microsoft.AspNetCore.DataProtection.Abstractions.dll
├── Microsoft.AspNetCore.DataProtection.Extensions.dll
├── Microsoft.AspNetCore.DataProtection.dll
├── Microsoft.AspNetCore.Diagnostics.Abstractions.dll
├── Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.dll
├── Microsoft.AspNetCore.Diagnostics.dll
├── Microsoft.AspNetCore.HostFiltering.dll
├── Microsoft.AspNetCore.Hosting.Abstractions.dll
├── Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
├── Microsoft.AspNetCore.Hosting.dll
├── Microsoft.AspNetCore.Html.Abstractions.dll
├── Microsoft.AspNetCore.Http.Abstractions.dll
├── Microsoft.AspNetCore.Http.Connections.Common.dll
├── Microsoft.AspNetCore.Http.Connections.dll
├── Microsoft.AspNetCore.Http.Extensions.dll
├── Microsoft.AspNetCore.Http.Features.dll
├── Microsoft.AspNetCore.Http.dll
├── Microsoft.AspNetCore.HttpOverrides.dll
├── Microsoft.AspNetCore.HttpsPolicy.dll
├── Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll
├── Microsoft.AspNetCore.Identity.UI.Views.dll
├── Microsoft.AspNetCore.Identity.UI.dll
├── Microsoft.AspNetCore.Identity.dll
├── Microsoft.AspNetCore.JsonPatch.dll
├── Microsoft.AspNetCore.Localization.Routing.dll
├── Microsoft.AspNetCore.Localization.dll
├── Microsoft.AspNetCore.MiddlewareAnalysis.dll
├── Microsoft.AspNetCore.Mvc.Abstractions.dll
├── Microsoft.AspNetCore.Mvc.ApiExplorer.dll
├── Microsoft.AspNetCore.Mvc.Core.dll
├── Microsoft.AspNetCore.Mvc.Cors.dll
├── Microsoft.AspNetCore.Mvc.DataAnnotations.dll
├── Microsoft.AspNetCore.Mvc.Formatters.Json.dll
├── Microsoft.AspNetCore.Mvc.Formatters.Xml.dll
├── Microsoft.AspNetCore.Mvc.Localization.dll
├── Microsoft.AspNetCore.Mvc.Razor.Extensions.dll
├── Microsoft.AspNetCore.Mvc.Razor.dll
├── Microsoft.AspNetCore.Mvc.RazorPages.dll
├── Microsoft.AspNetCore.Mvc.TagHelpers.dll
├── Microsoft.AspNetCore.Mvc.ViewFeatures.dll
├── Microsoft.AspNetCore.Mvc.dll
├── Microsoft.AspNetCore.NodeServices.dll
├── Microsoft.AspNetCore.Owin.dll
├── Microsoft.AspNetCore.Razor.Language.dll
├── Microsoft.AspNetCore.Razor.Runtime.dll
├── Microsoft.AspNetCore.Razor.dll
├── Microsoft.AspNetCore.ResponseCaching.Abstractions.dll
├── Microsoft.AspNetCore.ResponseCaching.dll
├── Microsoft.AspNetCore.ResponseCompression.dll
├── Microsoft.AspNetCore.Rewrite.dll
├── Microsoft.AspNetCore.Routing.Abstractions.dll
├── Microsoft.AspNetCore.Routing.dll
├── Microsoft.AspNetCore.Server.HttpSys.dll
├── Microsoft.AspNetCore.Server.IISIntegration.dll
├── Microsoft.AspNetCore.Server.Kestrel.Core.dll
├── Microsoft.AspNetCore.Server.Kestrel.Https.dll
├── Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.dll
├── Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
├── Microsoft.AspNetCore.Server.Kestrel.dll
├── Microsoft.AspNetCore.Session.dll
├── Microsoft.AspNetCore.SignalR.Common.dll
├── Microsoft.AspNetCore.SignalR.Core.dll
├── Microsoft.AspNetCore.SignalR.Protocols.Json.dll
├── Microsoft.AspNetCore.SignalR.dll
├── Microsoft.AspNetCore.SpaServices.Extensions.dll
├── Microsoft.AspNetCore.SpaServices.dll
├── Microsoft.AspNetCore.StaticFiles.dll
├── Microsoft.AspNetCore.WebSockets.dll
├── Microsoft.AspNetCore.WebUtilities.dll
├── Microsoft.AspNetCore.dll
├── Microsoft.CSharp.dll
├── Microsoft.CodeAnalysis.CSharp.dll
├── Microsoft.CodeAnalysis.Razor.dll
├── Microsoft.CodeAnalysis.dll
├── Microsoft.DotNet.PlatformAbstractions.dll
├── Microsoft.EntityFrameworkCore.Abstractions.dll
├── Microsoft.EntityFrameworkCore.Design.dll
├── Microsoft.EntityFrameworkCore.InMemory.dll
├── Microsoft.EntityFrameworkCore.Relational.dll
├── Microsoft.EntityFrameworkCore.SqlServer.dll
├── Microsoft.EntityFrameworkCore.dll
├── Microsoft.Extensions.Caching.Abstractions.dll
├── Microsoft.Extensions.Caching.Memory.dll
├── Microsoft.Extensions.Caching.SqlServer.dll
├── Microsoft.Extensions.Configuration.Abstractions.dll
├── Microsoft.Extensions.Configuration.Binder.dll
├── Microsoft.Extensions.Configuration.CommandLine.dll
├── Microsoft.Extensions.Configuration.EnvironmentVariables.dll
├── Microsoft.Extensions.Configuration.FileExtensions.dll
├── Microsoft.Extensions.Configuration.Ini.dll
├── Microsoft.Extensions.Configuration.Json.dll
├── Microsoft.Extensions.Configuration.KeyPerFile.dll
├── Microsoft.Extensions.Configuration.UserSecrets.dll
├── Microsoft.Extensions.Configuration.Xml.dll
├── Microsoft.Extensions.Configuration.dll
├── Microsoft.Extensions.DependencyInjection.Abstractions.dll
├── Microsoft.Extensions.DependencyInjection.dll
├── Microsoft.Extensions.DependencyModel.dll
├── Microsoft.Extensions.DiagnosticAdapter.dll
├── Microsoft.Extensions.FileProviders.Abstractions.dll
├── Microsoft.Extensions.FileProviders.Composite.dll
├── Microsoft.Extensions.FileProviders.Embedded.dll
├── Microsoft.Extensions.FileProviders.Physical.dll
├── Microsoft.Extensions.FileSystemGlobbing.dll
├── Microsoft.Extensions.Hosting.Abstractions.dll
├── Microsoft.Extensions.Hosting.dll
├── Microsoft.Extensions.Http.dll
├── Microsoft.Extensions.Identity.Core.dll
├── Microsoft.Extensions.Identity.Stores.dll
├── Microsoft.Extensions.Localization.Abstractions.dll
├── Microsoft.Extensions.Localization.dll
├── Microsoft.Extensions.Logging.Abstractions.dll
├── Microsoft.Extensions.Logging.Configuration.dll
├── Microsoft.Extensions.Logging.Console.dll
├── Microsoft.Extensions.Logging.Debug.dll
├── Microsoft.Extensions.Logging.EventSource.dll
├── Microsoft.Extensions.Logging.TraceSource.dll
├── Microsoft.Extensions.Logging.dll
├── Microsoft.Extensions.ObjectPool.dll
├── Microsoft.Extensions.Options.ConfigurationExtensions.dll
├── Microsoft.Extensions.Options.dll
├── Microsoft.Extensions.Primitives.dll
├── Microsoft.Extensions.WebEncoders.dll
├── Microsoft.IdentityModel.Logging.dll
├── Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
├── Microsoft.IdentityModel.Protocols.WsFederation.dll
├── Microsoft.IdentityModel.Protocols.dll
├── Microsoft.IdentityModel.Tokens.Saml.dll
├── Microsoft.IdentityModel.Tokens.dll
├── Microsoft.IdentityModel.Xml.dll
├── Microsoft.Net.Http.Headers.dll
├── Microsoft.VisualBasic.dll
├── Microsoft.Win32.Primitives.dll
├── Microsoft.Win32.Registry.dll
├── Newtonsoft.Json.Bson.dll
├── Newtonsoft.Json.dll
├── Remotion.Linq.dll
├── SOS.NETCore.dll
├── SelfContainedApp
├── SelfContainedApp.deps.json
├── SelfContainedApp.dll
├── SelfContainedApp.pdb
├── SelfContainedApp.runtimeconfig.json
├── System.AppContext.dll
├── System.Buffers.dll
├── System.Collections.Concurrent.dll
├── System.Collections.Immutable.dll
├── System.Collections.NonGeneric.dll
├── System.Collections.Specialized.dll
├── System.Collections.dll
├── System.ComponentModel.Annotations.dll
├── System.ComponentModel.DataAnnotations.dll
├── System.ComponentModel.EventBasedAsync.dll
├── System.ComponentModel.Primitives.dll
├── System.ComponentModel.TypeConverter.dll
├── System.ComponentModel.dll
├── System.Configuration.dll
├── System.Console.dll
├── System.Core.dll
├── System.Data.Common.dll
├── System.Data.SqlClient.dll
├── System.Data.dll
├── System.Diagnostics.Contracts.dll
├── System.Diagnostics.Debug.dll
├── System.Diagnostics.DiagnosticSource.dll
├── System.Diagnostics.FileVersionInfo.dll
├── System.Diagnostics.Process.dll
├── System.Diagnostics.StackTrace.dll
├── System.Diagnostics.TextWriterTraceListener.dll
├── System.Diagnostics.Tools.dll
├── System.Diagnostics.TraceSource.dll
├── System.Diagnostics.Tracing.dll
├── System.Drawing.Primitives.dll
├── System.Drawing.dll
├── System.Dynamic.Runtime.dll
├── System.Globalization.Calendars.dll
├── System.Globalization.Extensions.dll
├── System.Globalization.Native.so
├── System.Globalization.dll
├── System.IO.Compression.Brotli.dll
├── System.IO.Compression.FileSystem.dll
├── System.IO.Compression.Native.a
├── System.IO.Compression.Native.so
├── System.IO.Compression.ZipFile.dll
├── System.IO.Compression.dll
├── System.IO.FileSystem.AccessControl.dll
├── System.IO.FileSystem.DriveInfo.dll
├── System.IO.FileSystem.Primitives.dll
├── System.IO.FileSystem.Watcher.dll
├── System.IO.FileSystem.dll
├── System.IO.IsolatedStorage.dll
├── System.IO.MemoryMappedFiles.dll
├── System.IO.Pipelines.dll
├── System.IO.Pipes.AccessControl.dll
├── System.IO.Pipes.dll
├── System.IO.UnmanagedMemoryStream.dll
├── System.IO.dll
├── System.IdentityModel.Tokens.Jwt.dll
├── System.Interactive.Async.dll
├── System.Linq.Expressions.dll
├── System.Linq.Parallel.dll
├── System.Linq.Queryable.dll
├── System.Linq.dll
├── System.Memory.dll
├── System.Native.a
├── System.Native.so
├── System.Net.Http.Formatting.dll
├── System.Net.Http.Native.a
├── System.Net.Http.Native.so
├── System.Net.Http.dll
├── System.Net.HttpListener.dll
├── System.Net.Mail.dll
├── System.Net.NameResolution.dll
├── System.Net.NetworkInformation.dll
├── System.Net.Ping.dll
├── System.Net.Primitives.dll
├── System.Net.Requests.dll
├── System.Net.Security.Native.a
├── System.Net.Security.Native.so
├── System.Net.Security.dll
├── System.Net.ServicePoint.dll
├── System.Net.Sockets.dll
├── System.Net.WebClient.dll
├── System.Net.WebHeaderCollection.dll
├── System.Net.WebProxy.dll
├── System.Net.WebSockets.Client.dll
├── System.Net.WebSockets.WebSocketProtocol.dll
├── System.Net.WebSockets.dll
├── System.Net.dll
├── System.Numerics.Vectors.dll
├── System.Numerics.dll
├── System.ObjectModel.dll
├── System.Private.CoreLib.dll
├── System.Private.DataContractSerialization.dll
├── System.Private.Uri.dll
├── System.Private.Xml.Linq.dll
├── System.Private.Xml.dll
├── System.Reflection.DispatchProxy.dll
├── System.Reflection.Emit.ILGeneration.dll
├── System.Reflection.Emit.Lightweight.dll
├── System.Reflection.Emit.dll
├── System.Reflection.Extensions.dll
├── System.Reflection.Metadata.dll
├── System.Reflection.Primitives.dll
├── System.Reflection.TypeExtensions.dll
├── System.Reflection.dll
├── System.Resources.Reader.dll
├── System.Resources.ResourceManager.dll
├── System.Resources.Writer.dll
├── System.Runtime.CompilerServices.Unsafe.dll
├── System.Runtime.CompilerServices.VisualC.dll
├── System.Runtime.Extensions.dll
├── System.Runtime.Handles.dll
├── System.Runtime.InteropServices.RuntimeInformation.dll
├── System.Runtime.InteropServices.WindowsRuntime.dll
├── System.Runtime.InteropServices.dll
├── System.Runtime.Loader.dll
├── System.Runtime.Numerics.dll
├── System.Runtime.Serialization.Formatters.dll
├── System.Runtime.Serialization.Json.dll
├── System.Runtime.Serialization.Primitives.dll
├── System.Runtime.Serialization.Xml.dll
├── System.Runtime.Serialization.dll
├── System.Runtime.dll
├── System.Security.AccessControl.dll
├── System.Security.Claims.dll
├── System.Security.Cryptography.Algorithms.dll
├── System.Security.Cryptography.Cng.dll
├── System.Security.Cryptography.Csp.dll
├── System.Security.Cryptography.Encoding.dll
├── System.Security.Cryptography.Native.OpenSsl.a
├── System.Security.Cryptography.Native.OpenSsl.so
├── System.Security.Cryptography.OpenSsl.dll
├── System.Security.Cryptography.Pkcs.dll
├── System.Security.Cryptography.Primitives.dll
├── System.Security.Cryptography.X509Certificates.dll
├── System.Security.Cryptography.Xml.dll
├── System.Security.Permissions.dll
├── System.Security.Principal.Windows.dll
├── System.Security.Principal.dll
├── System.Security.SecureString.dll
├── System.Security.dll
├── System.ServiceModel.Web.dll
├── System.ServiceProcess.dll
├── System.Text.Encoding.CodePages.dll
├── System.Text.Encoding.Extensions.dll
├── System.Text.Encoding.dll
├── System.Text.Encodings.Web.dll
├── System.Text.RegularExpressions.dll
├── System.Threading.Channels.dll
├── System.Threading.Overlapped.dll
├── System.Threading.Tasks.Dataflow.dll
├── System.Threading.Tasks.Extensions.dll
├── System.Threading.Tasks.Parallel.dll
├── System.Threading.Tasks.dll
├── System.Threading.Thread.dll
├── System.Threading.ThreadPool.dll
├── System.Threading.Timer.dll
├── System.Threading.dll
├── System.Transactions.Local.dll
├── System.Transactions.dll
├── System.ValueTuple.dll
├── System.Web.HttpUtility.dll
├── System.Web.dll
├── System.Windows.dll
├── System.Xml.Linq.dll
├── System.Xml.ReaderWriter.dll
├── System.Xml.Serialization.dll
├── System.Xml.XDocument.dll
├── System.Xml.XPath.XDocument.dll
├── System.Xml.XPath.dll
├── System.Xml.XmlDocument.dll
├── System.Xml.XmlSerializer.dll
├── System.Xml.dll
├── System.dll
├── WindowsBase.dll
├── appsettings.Development.json
├── appsettings.json
├── createdump
├── libclrjit.so
├── libcoreclr.so
├── libcoreclrtraceptprovider.so
├── libdbgshim.so
├── libhostfxr.so
├── libhostpolicy.so
├── libmscordaccore.so
├── libmscordbi.so
├── libsos.so
├── libsosplugin.so
├── mscorlib.dll
├── netstandard.dll
├── sosdocsunix.txt
└── web.config

0 directories, 353 files

長いですが、このpublishディレクトリの中身単独で動作します。

コンソールアプリを Linux で動かしてみる

Docker で .NET Core ランタイムの入っていない Alpine Linux を用意しその上で Self-Contained でビルドしたアプリを動かしてみます。

Dockerfile
# .NET Core SDK 上でコンソールアプリをビルドします。
# dotnet new consoleは"Hello World"を返すコンソールアプリのプロジェクトを作成します。
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /app
RUN dotnet new console -n hello && \
    dotnet publish hello -c Release -o out -r linux-musl-x64 --self-contained true

# `runtime-deps:2.1-alpine`には .NET Coreに必要なネイティブの依存関係が含まれています。
# .NET Core ランタイムは含まれていません。
FROM mcr.microsoft.com/dotnet/core/runtime-deps:2.1-alpine
WORKDIR /app
COPY --from=build /app/hello/out ./
ENTRYPOINT ["./hello"]

イメージをビルドします。

$ docker build .
Sending build context to Docker daemon  1.726MB
Step 1/7 : FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
2.1: Pulling from dotnet/core/sdk
e79bb959ec00: Pull complete
d4b7902036fe: Pull complete
1b2a72d4e030: Pull complete
d54db43011fd: Pull complete
1e52e76f4f6d: Pull complete
d8de6695a046: Pull complete
6d1514544b63: Pull complete
Digest: sha256:17e2e7daa1594fb08d08bafa7d372c18bda14a7542781bb5695a65442969a915
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:2.1
 ---> ff665cc04279
Step 2/7 : WORKDIR /app
 ---> Running in 89ec38d10d43
Removing intermediate container 89ec38d10d43
 ---> c4ce87166dea
Step 3/7 : RUN dotnet new console -n hello &&     dotnet publish hello -c Release -o out -r linux-musl-x64 --self-contained true
 ---> Running in 1809562ef739
Getting ready...
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on hello/hello.csproj...
  Restoring packages for /app/hello/hello.csproj...
  Generating MSBuild file /app/hello/obj/hello.csproj.nuget.g.props.
  Generating MSBuild file /app/hello/obj/hello.csproj.nuget.g.targets.
  Restore completed in 434.69 ms for /app/hello/hello.csproj.

Restore succeeded.

Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /app/hello/hello.csproj...
  Installing Microsoft.NETCore.DotNetAppHost 2.1.9.
  Installing Microsoft.NETCore.DotNetHostResolver 2.1.9.
  Installing Microsoft.NETCore.DotNetHostPolicy 2.1.9.
  Installing Microsoft.NETCore.Platforms 2.1.3.
  Installing Microsoft.NETCore.Targets 2.0.0.
  Installing Microsoft.NETCore.App 2.1.9.
  Installing runtime.linux-musl-x64.Microsoft.NETCore.DotNetAppHost 2.1.9.
  Installing runtime.linux-musl-x64.Microsoft.NETCore.DotNetHostResolver 2.1.9.
  Installing runtime.linux-musl-x64.Microsoft.NETCore.DotNetHostPolicy 2.1.9.
  Installing runtime.linux-musl-x64.Microsoft.NETCore.App 2.1.9.
  Generating MSBuild file /app/hello/obj/hello.csproj.nuget.g.props.
  Generating MSBuild file /app/hello/obj/hello.csproj.nuget.g.targets.
  Restore completed in 5.37 sec for /app/hello/hello.csproj.
  hello -> /app/hello/bin/Release/netcoreapp2.1/linux-musl-x64/hello.dll
  hello -> /app/hello/out/
Removing intermediate container 1809562ef739
 ---> 951c93895738
Step 4/7 : FROM mcr.microsoft.com/dotnet/core/runtime-deps:2.1-alpine
2.1-alpine: Pulling from dotnet/core/runtime-deps
5d20c808ce19: Pull complete
e0981f598641: Pull complete
Digest: sha256:c5adb60a9733e007d04afba928249923d0f1d89b55bf1cff21b146cfe7d16811
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/runtime-deps:2.1-alpine
 ---> 65777c2a0615
Step 5/7 : WORKDIR /app
 ---> Running in 72b4d12b01cf
Removing intermediate container 72b4d12b01cf
 ---> bf7d5574fcd5
Step 6/7 : COPY --from=build /app/hello/out ./
 ---> ab5ae44c9716
Step 7/7 : ENTRYPOINT ["./hello"]
 ---> Running in 4af12e0851e7
Removing intermediate container 4af12e0851e7
 ---> 7ae244222d04
Successfully built 7ae244222d04

コンテナを起動します。

$ docker run 7ae244222d04
Hello World!

.NET Core がインストールされていない環境(Alpine Linux)で.NET Core アプリが動くことが確認できました。

32
41
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
41