Skip to content

Instantly share code, notes, and snippets.

@NileshGule
Last active December 7, 2017 15:52
Show Gist options
  • Save NileshGule/78cd86c49deff2b2bedf113d0aba0649 to your computer and use it in GitHub Desktop.
Save NileshGule/78cd86c49deff2b2bedf113d0aba0649 to your computer and use it in GitHub Desktop.
Gist related to the blogpost on upgrading to Alpine based docker image
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0-preview1-25919-02</RuntimeFrameworkVersion>
<!--<RuntimeIdentifiers>win8-x64;ubuntu.16.10-x64;osx.10.12-x64</RuntimeIdentifiers>-->
</PropertyGroup>
<ItemGroup>
<Compile Remove="releaseOutput\**" />
<Content Remove="releaseOutput\**" />
<EmbeddedResource Remove="releaseOutput\**" />
<None Remove="releaseOutput\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Properties\PublishProfiles\FolderProfile.pubxml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- <TargetFramework>netcoreapp2.0</TargetFramework> -->
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0-preview1-25919-02</RuntimeFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
FROM microsoft/dotnet-nightly:2.1-sdk AS build-env
WORKDIR /MyFirstCoreWebApi
COPY *.csproj ./
COPY NuGet.config ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o releaseOutput --no-restore
#build runtime image
FROM microsoft/dotnet-nightly:2.1-runtime-alpine
WORKDIR /MyFirstCoreWebApi
COPY --from=build-env /MyFirstCoreWebApi/releaseOutput ./
EXPOSE 8080
ENTRYPOINT ["dotnet", "CoreWebAPI.dll"]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace CoreWebAPI
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:8080")
.UseStartup<Startup>()
.Build();
}
}
FROM microsoft/dotnet-nightly:2.1-sdk AS build-env
WORKDIR /MyFirstMvcCoreApp
COPY *.csproj ./
COPY NuGet.config ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o releaseOutput --no-restore
#build runtime image
FROM microsoft/dotnet-nightly:2.1-runtime-alpine
WORKDIR /MyFirstMvcCoreApp
COPY --from=build-env /MyFirstMvcCoreApp/releaseOutput ./
EXPOSE 80
ENTRYPOINT ["dotnet", "CoreMVC.dll"]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace CoreMVC
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:80")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment