Skip to content

Instantly share code, notes, and snippets.

@brthor
Last active March 7, 2018 03:15
Show Gist options
  • Save brthor/707e5dd4bf19dd605934cfc47db356bf to your computer and use it in GitHub Desktop.
Save brthor/707e5dd4bf19dd605934cfc47db356bf to your computer and use it in GitHub Desktop.
.NET core copy/paste deploy to linux by adding system libs.

Overview

When you publish a self-contained dotnet linux app for .net core 2.0, and run it on a brand new machine, you'll get this error:

Failed to load', error: libunwind.so.8: cannot open shared object file: No such file or directory
Failed to bind to CoreCLR at '/export/libcoreclr.so'

You can solve this by installing system packages, but for a truly self-contained publish, pull the missing libraries from the microsoft docker image, and into your app's output. You can put them in the publish directory and distribute them with your app.

Creating the project:

$ mkdir test && cd test
$ dotnet new console && dotnet publish -r linux-x64 --self-contained -o bin

If you run it on linux, expected result:

$ docker run -it -v $(pwd)/bin:/export ubuntu:latest /export/export
Failed to load', error: libunwind.so.8: cannot open shared object file: No such file or directory
Failed to bind to CoreCLR at '/export/libcoreclr.so'

Pull the libraries via docker (libunwind and libicu) and to your publish directory:

$ docker run -v $(pwd)/bin:/export microsoft/dotnet:2.0.0-sdk bash -c "cp /usr/lib/x86_64-linux-gnu/libicu* /export/"

$ docker run -v $(pwd)/bin:/export microsoft/dotnet:2.0.0-sdk bash -c "cp /usr/lib/x86_64-linux-gnu/libunwind* /export/"

Re-test:

$ docker run -it -v $(pwd)/bin:/export ubuntu:latest bash -c "LD_LIBRARY_PATH=/export /export/export"
Hello World

Success!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment