Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Getting the error "Unable to load DLL 'libdl'" on Ubuntu docker container with container image, microsoft/aspnetcore-build:2.0 #40

Open
BharatRajMeriyala opened this issue Dec 20, 2017 · 15 comments

Comments

@BharatRajMeriyala
Copy link

BharatRajMeriyala commented Dec 20, 2017

I am trying to generate the excel sheet, using EPPlus.Core in dotnet core 2.0 framework. The generation works fine on local machine running windows. When I test the same on Ubuntu docker images, it fails with the below exception:

Unable to load DLL 'libdl': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at Interop.Libdl.dlopen(String fileName, Int32 flag)
at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()
at System.Drawing.SafeNativeMethods.Gdip..cctor()

The same used to work fine when I used the dotnet core 1.1, with libgdiplus being explicitely installed. But this setup fails with dotnet core 2.0.

The complete docker file is as below:

FROM microsoft/aspnetcore-build:2.0

RUN apt-get update
RUN apt-get install -y libgdiplus

RUN npm install typings -g

COPY . /app
WORKDIR /app/MyWeb

RUN ["dotnet", "--info"]
RUN ["dotnet", "restore"]

EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000

RUN ["dotnet", "publish"]

WORKDIR /app/MyWeb/bin/Debug/netcoreapp2.0/publish

ENTRYPOINT ["dotnet", "MyWeb.dll"]

@VahidN
Copy link
Owner

VahidN commented Dec 20, 2017

symlink /lib64/libdl.so.2 to /lib64/libdl.so
More info

@BharatRajMeriyala
Copy link
Author

BharatRajMeriyala commented Dec 20, 2017

I am not sure its possible to create a symlink in docker container.

https://stackoverflow.com/questions/31881904/docker-follow-symlink-outside-context

And I updated my docker file like below, I still get the same error. I am using Ubuntu 16.04 in my production environment.


FROM microsoft/aspnetcore-build:2.0

RUN apt-get update
RUN apt-get install -y libgdiplus

RUN npm install typings -g

RUN ln -s /lib64/libdl.so.2 /lib64/libdl.so

COPY . /app
WORKDIR /app/MyWeb

RUN ["dotnet", "--info"]
RUN ["dotnet", "restore"]

EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000

RUN ["dotnet", "publish"]

WORKDIR /app/MyWeb/bin/Debug/netcoreapp2.0/publish

ENTRYPOINT ["dotnet", "MyWeb.dll"]

@dustdragonpzc
Copy link

I also have some problem. use ln -s /lib64/libdl.so.2 /lib64/libdl.so , But it doesn't work in the Docker , I am using Centos 7.3 64bit

@VahidN
Copy link
Owner

VahidN commented Dec 28, 2017

Revert to v1.5.2 which uses CoreCompat.System.Drawing.v2 for now. v1.5.4 uses Microsoft's System.Drawing.Common library. It's in the preview phase right now.

 Install-Package EPPlus.Core -Version 1.5.2

Also you need to install libgdiplus too.

For Ubuntu 16.04 and above:
    apt-get install libgdiplus
    cd /usr/lib
    ln -s libgdiplus.so gdiplus.dll

@dustdragonpzc
Copy link

when I run install libgdiplus ,I only find libgdiplus.so.0 in /usr/lib64, not find libgdiplus.so ,then I run
cd /usr/lib64
ln -s libgdiplus.so.0 gdiplus.dll, but it also dosen't work
I am using Centos 7.3 64bit

@VahidN
Copy link
Owner

VahidN commented Dec 29, 2017

For CentOS 7 and above:

    yum install autoconf automake libtool
    yum install freetype-devel fontconfig libXft-devel
    yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
    yum install glib2-devel cairo-devel
    git clone https://github.com/mono/libgdiplus
    cd libgdiplus
    ./autogen.sh
    make
    make install
    cd /usr/lib64/
    ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

@dustdragonpzc
Copy link

dustdragonpzc commented Dec 29, 2017

why the command yum install libgdiplus dosen't work,must execute the commands you write

@dustdragonpzc
Copy link

dustdragonpzc commented Dec 29, 2017

I did it according to what you said

root@izuf6fv1dbvhuu4bilrjg5z:~# find / -name libgdiplus.so
/usr/local/lib/libgdiplus.so
/root/libgdiplus/src/.libs/libgdiplus.so
root@izuf6fv1dbvhuu4bilrjg5z:~# find / -name gdiplus.dll
/usr/lib64/gdiplus.dll

but the excption is also existence
The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus': The specified module or one of its dependencies could not be found.

@dustdragonpzc
Copy link

I according to http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/
I slove this problem thank for VahidN

@fjunqueira
Copy link

fjunqueira commented Jan 19, 2018

The only way i was able to work around this issue was by reverting to v1.5.2 and adding the following symlink: ln -s libgdiplus.so gdiplus.dll to my Docker image

Thanks @VahidN

@VahidN
Copy link
Owner

VahidN commented Mar 5, 2018

If you are using 1.5.4, update your System.Drawing.Common dependency. This official package has 3 updates now:
https://www.nuget.org/packages/System.Drawing.Common/

@VahidN
Copy link
Owner

VahidN commented Mar 5, 2018

About Unable to load DLL 'libdl' error in containers, they are suggesting:

  • Install libgdiplus and libc6-dev in your container (If you're on Ubuntu or Debian, you can try to install the libc6-dev package to get libdl.so).
  • Check /usr/lib/x86_64-linux-gnu/libdl.so file exists inside your container.
  • If it still fails, you can try setting LD_LIBRARY_PATH to $LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu but that should be included already.
  • If that still fails, you can set the LD_DEBUG environment variable to libs in your Dockerfile, restart your container.

@taobaohi
Copy link

FROM microsoft/aspnetcore
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
WORKDIR /app
COPY /app ./
EXPOSE 8082
ENTRYPOINT ["dotnet", "WebApp.dll"]

is ok

@justmine66
Copy link

justmine66 commented Jun 14, 2018

samples: dotnet-ascpnetcore-runtime:2.1
xx.csproj file:
image
Dockerfile file:
image
or directly use the images i had buit: https://hub.docker.com/r/justmine/dotnet-aspnetcore-runtime-gdiplus
it is ok !!! 亲测可用
image

@xing-zheng
Copy link

xing-zheng commented Jun 24, 2018

@justmine66 It works for me, but package lsof may be unnecessary, and make symbol link for gidplus.dll is also unnecessary.

FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY ./EPPlusOnDocker .

RUN apt-get update \
    && apt-get install -y --no-install-recommends libgdiplus libc6-dev \
    && rm -rf /var/lib/apt/lists/*
    
ENTRYPOINT [ "dotnet", "EPPlusOnDocker.dll" ]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants