This repository was archived by the owner on Mar 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 385
Add sample to illustrate usage of the Alpine preview images #94
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| bin/ | ||
| obj/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FROM microsoft/dotnet-nightly:2.1-sdk AS build-env | ||
| WORKDIR /app | ||
|
|
||
| # copy csproj and restore as distinct layers | ||
| COPY *.csproj ./ | ||
| COPY NuGet.config ./ | ||
| RUN dotnet restore | ||
|
|
||
| # copy everything else and build | ||
| COPY . ./ | ||
| RUN dotnet publish -c Release -o out --no-restore | ||
|
|
||
|
|
||
| # build runtime image | ||
| FROM microsoft/dotnet-nightly:2.1-runtime-alpine | ||
| WORKDIR /app | ||
| COPY --from=build-env /app/out ./ | ||
| ENTRYPOINT ["dotnet", "dotnetapp.dll"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| FROM microsoft/dotnet-nightly:2.1-sdk AS build-env | ||
| WORKDIR /app | ||
|
|
||
| # copy csproj and restore as distinct layers | ||
| COPY *.csproj ./ | ||
| COPY NuGet.config ./ | ||
| RUN dotnet restore | ||
|
|
||
| # copy everything else and build | ||
| COPY . ./ | ||
| RUN dotnet publish -c Release -o out --no-restore | ||
|
|
||
|
|
||
| # build runtime image | ||
| FROM microsoft/dotnet-nightly:2.1-runtime-alpine | ||
|
|
||
| ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false | ||
| RUN apk add --no-cache icu-libs | ||
|
|
||
| ENV LC_ALL en_US.UTF-8 | ||
| ENV LANG en_US.UTF-8 | ||
|
|
||
| WORKDIR /app | ||
| COPY --from=build-env /app/out ./ | ||
| ENTRYPOINT ["dotnet", "dotnetapp.dll"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <packageSources> | ||
| <!--To inherit the global NuGet package sources remove the <clear/> line below --> | ||
| <clear /> | ||
| <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" /> | ||
| <add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
| </packageSources> | ||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using System.Globalization; | ||
| using static System.Console; | ||
|
|
||
| public static class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| string message = "Dotnet-bot: Welcome to using .NET Core!"; | ||
|
|
||
| if (args.Length > 0) | ||
| { | ||
| message = String.Join(" ", args); | ||
| } | ||
|
|
||
| WriteLine(GetBot(message)); | ||
| WriteLine("**Environment**"); | ||
| WriteLine($"Platform: .NET Core 2.0"); | ||
| WriteLine($"OS: {RuntimeInformation.OSDescription}"); | ||
| WriteLine($"Culture: {CultureInfo.CurrentCulture.DisplayName}"); | ||
| WriteLine(); | ||
| } | ||
|
|
||
| public static string GetBot(string message) | ||
| { | ||
| string bot = $"\n {message}"; | ||
| bot += @" | ||
| __________________ | ||
| \ | ||
| \ | ||
| .... | ||
| ....' | ||
| .... | ||
| .......... | ||
| .............'..'.. | ||
| ................'..'..... | ||
| .......'..........'..'..'.... | ||
| ........'..........'..'..'..... | ||
| .'....'..'..........'..'.......'. | ||
| .'..................'... ...... | ||
| . ......'......... ..... | ||
| . ...... | ||
| .. . .. ...... | ||
| .... . ....... | ||
| ...... ....... ............ | ||
| ................ ...................... | ||
| ........................'................ | ||
| ......................'..'...... ....... | ||
| .........................'..'..... ....... | ||
| ........ ..'.............'..'.... .......... | ||
| ..'..'... ...............'....... .......... | ||
| ...'...... ...... .......... ...... ....... | ||
| ........... ....... ........ ...... | ||
| ....... '...'.'. '.'.'.' .... | ||
| ....... .....'.. ..'..... | ||
| .. .......... ..'........ | ||
| ............ .............. | ||
| ............. '.............. | ||
| ...........'.. .'.'............ | ||
| ............... .'.'............. | ||
| .............'.. ..'..'........... | ||
| ............... .'.............. | ||
| ......... .............. | ||
| ..... | ||
|
|
||
| "; | ||
| return bot; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # .NET Core Docker Alpine Production Sample (Preview) | ||
|
|
||
| This .NET Core Docker sample demonstrates a best practice pattern for building Alpine based Docker images for .NET Core apps for production. The primary goal of Alpine is very small deployments. Images can be pulled quicker and will have a smaller attack surface area. The .NET Core Alpine Docker images are currently in preview. See the [.NET Core Alpine Docker Image announcement](https://gist.github.com/richlander/9529644df6df25e902682aee7f5c0846) for additional details. | ||
|
|
||
| The [sample Dockerfile](Dockerfile) creates an .NET Core application Docker image based off of the [.NET Core Runtime Alpine Preview Docker image](https://hub.docker.com/r/microsoft/dotnet-nightly/). | ||
|
|
||
| It uses the [Docker multi-stage build feature](https://github.com/dotnet/announcements/issues/18) to build the sample in a container based on the larger [.NET Core SDK Docker base image](https://hub.docker.com/r/microsoft/dotnet/) and then copies the final build result into a Docker image based on the smaller [.NET Core Docker Runtime base image](https://hub.docker.com/r/microsoft/dotnet/). The SDK image contains tools that are required to build applications while the runtime image does not. | ||
|
|
||
| This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker). You need the latest Windows 10 or Windows Server 2016 to use [Windows containers](http://aka.ms/windowscontainers). The instructions assume you have the [Git](https://git-scm.com/downloads) client installed. | ||
|
|
||
| ## Getting the sample | ||
|
|
||
| The easiest way to get the sample is by cloning the samples repository with git, using the following instructions. You can also just download the repository (it is small) as a zip from the [.NET Core Docker samples](https://github.com/dotnet/dotnet-docker-samples/) respository. | ||
|
|
||
| ```console | ||
| git clone https://github.com/dotnet/dotnet-docker-samples/ | ||
| ``` | ||
|
|
||
| ## Build and run the sample with Docker | ||
|
|
||
| You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository. | ||
|
|
||
| ```console | ||
| cd dotnetapp-prod-alpine-preview | ||
| docker build -t dotnetapp-prod-alpine-preview . | ||
| docker run --rm dotnetapp-prod-alpine-previewHello .NET Core from Docker | ||
| ``` | ||
|
|
||
| Note: The instructions above work only with Linux containers. | ||
|
|
||
| ## Build and run the sample without the Globalization Invariant Mode | ||
|
|
||
| The Alpine based .NET Core Runtime Docker image has the [.NET Core 2.0 Globalization Invariant Mode](https://github.com/dotnet/announcements/issues/20) enabled in order to reduce the default size of the image. Use cases that cannot tolerate Globalization Invariant Mode can reset the `DOTNET_SYSTEM_GLOBALIZATION_INVARIANT` environment variable and install the required ICU package. The [Globalization Dockerfile](Dockerfile.globalization) illustrates how this can be done. | ||
|
|
||
| You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository. | ||
|
|
||
| ```console | ||
| cd dotnetapp-prod-alpine-preview | ||
| docker build -t dotnetapp-prod-alpine-preview -f Dockerfile.globalization . | ||
| docker run --rm dotnetapp-prod-alpine-previewHello .NET Core from Docker | ||
| ``` | ||
|
|
||
| Note: The instructions above work only with Linux containers. | ||
|
|
||
| ## Docker Images used in this sample | ||
|
|
||
| The following Docker images are used in this sample | ||
|
|
||
| * [microsoft/dotnet-nightly:2.1-sdk](https://hub.docker.com/r/microsoft/dotnet-nightly) | ||
| * [microsoft/dotnet-nightly:2.1-runtime-alpine](https://hub.docker.com/r/microsoft/dotnet-nightly) | ||
|
|
||
| ## Related Resources | ||
|
|
||
| * [ASP.NET Core Production Docker sample](../aspnetapp/README.md) | ||
| * [.NET Core Docker samples](../README.md) | ||
| * [.NET Framework Docker samples](https://github.com/Microsoft/dotnet-framework-docker-samples) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> | ||
|
|
||
| <PropertyGroup> | ||
|
|
||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| <RuntimeFrameworkVersion>2.1.0-preview1-25919-02</RuntimeFrameworkVersion> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep - as well as the globalization steps.