Skip to content

Instantly share code, notes, and snippets.

@leapingbytes
Created May 2, 2019 14:32
Show Gist options
  • Save leapingbytes/b046a1309ca8fa6c75e2b2bf6dc45720 to your computer and use it in GitHub Desktop.
Save leapingbytes/b046a1309ca8fa6c75e2b2bf6dc45720 to your computer and use it in GitHub Desktop.
Dockerizing simple c# app
docker build -t xxx .
FROM microsoft/dotnet:2.2-sdk as sdk
# RUN dotnet tool install -g dotnet-warp
RUN curl -Lo /root/warp-packer https://github.com/dgiagio/warp/releases/download/v0.3.0/linux-x64.warp-packer
RUN chmod +x /root/warp-packer
RUN mkdir /build
COPY Program.cs MyApp.csproj /build/
WORKDIR /build
RUN dotnet restore
# RUN /root/.dotnet/tools/dotnet-warp
RUN dotnet publish -c Release -r linux-musl-x64 --self-contained
RUN /root/warp-packer --arch linux-x64 --input_dir bin/Release/netcoreapp2.2/linux-musl-x64/publish --exec MyApp --output MyApp
FROM scratch
WORKDIR /root/
COPY --from=sdk /build/MyApp .
CMD ["./MyApp"]
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
namespace list_tutorial
{
class Program
{
static void Main(string[] args)
{
var names = new List<string> { "<name>", "Ana", "Felipe" };
foreach (var name in names)
{
Console.WriteLine($"Hello {name.ToUpper()}!");
}
}
}
}
docker run xxx:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment