Should be able to create thumbnail images using the Bitmap class from System.Drawing.Common
Get error:
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
A little research says we need to install libgdiplus and libc6-dev. I used the following to attempt that:
# install libgdiplus for System.Drawing
RUN apt-get update && \
apt-get install -y --allow-unauthenticated libgdiplus libc6-dev
# install x11 for System.Drawing
RUN apt-get update && \
apt-get install -y --allow-unauthenticated libx11-dev
That fails with errors about hashes not matching or size being greater than expected
docker versionClient:
Version: 18.05.0-ce
API version: 1.37
Go version: go1.9.5
Git commit: f150324
Built: Wed May 9 22:12:05 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.05.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.10.1
Git commit: f150324
Built: Wed May 9 22:20:16 2018
OS/Arch: linux/amd64
Experimental: true
docker infoContainers: 33
Running: 4
Paused: 0
Stopped: 29
Images: 134
Server Version: 18.05.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.93-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155d46f121
ID: JJAR:3NTY:2RV6:SQ7D:NF45:XVEM:QA3J:SHDB:ZEJS:BHIC:X3D2:VRT5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 51
Goroutines: 70
System Time: 2018-07-07T02:51:21.9916291Z
EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
It turns out that I couldn't add that library from windows machine (where I was trying to build the container). After I pushed the Dockerfile out to a linux build agent, it was able to add the library and build properly. This causes some problem because I can't build the container the locally for development purposes but I can work around that for now.
@sddev-dotnet - Hmm, sounds like the underlying issue was an intermittent issue with the apt feed you are using to pull from. Try it again on your Windows machine. I just tried a Bitmap sample app and everything worked as expected from both a Windows and Linux Docker host. FYI - I was using the microsoft/dotnet:2.1-sdk image which is based on Debian Stretch.
One tip regarding the pattern used to install the apt packages. Make sure you cleanup the apt cache within your Dockerfile as this bloats the resulting image. It is a Docker best practice.
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
Closing but feel free to continue the conversation.
I am having the same problem. I am trying to run tests in a GitLab CI task using the microsoft/dotnet:2.1-sdk (Debian Stretch) Docker image.
@MichaelSimons do I understand you correctly that this is working for you without building your own Docker image?
@jugglingthebits - No, the microsoft/dotnet images do not contain the native libgdiplus library required by System.Drawing. You will need to add this yourself. For my scenario, I added the following to my Dockerfile
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
@MichaelSimons Thanks for the workaround! IMHO this is a bug in the docker image though, why did you close this?
The runtime Dockerfiles only install the core dependencies. There are additional dependencies that are required for non-mainline scenarios that are not included by default such as libgdiplus. The Docker images align with the product installers in this way. We did this in order to keep the runtime images to a reasonable size (something we receive a fair amount of feedback on).
Ah ok, tradeoffs :-)
Just my 2 cents, it would have helped me if there was documentation referenced from https://hub.docker.com/r/microsoft/dotnet/ where "non-mainline" apis were listed together with the packages required to enable them.
@jugglingthebits - That is a good suggestion. Would you mind logging a new issue specific to documenting these non-mainline scenarios? Please reference this issue. Thanks for the feedback!
This is my Dockerfile:
```
FROM docker.io/microsoft/dotnet:2.1-aspnetcore-runtime
COPY . /app
WORKDIR /app
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak &&
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list &&
echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list &&
echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list &&
echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
RUN apt-get update
&& apt-get install -y --allow-unauthenticated
libgdiplus
# libc6-dev
# libgdiplus
# libx11-dev
&& rm -rf /var/lib/apt/lists/*
CMD ["dotnet", "Thinktank.Web.dll"]
```
@autukill Dockerfile worked for me.
My Dockerfile starts with FROM microsoft/dotnet:2.1-sdk AS builder-stage. But remember to put @autukill fix after the runtime stage (FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime-stage in my case)
Hi!
I have the same problema but when i insall all the libgdiplus libreary then i have another error about Kernel32, im using dotnet core 2.0, is there any suggestion?
"Unable to load shared library 'kernel32.dll or one of its dependencies. In order to help diagnose problems, consider setting the LD_DEBUG enviroment variable: kernel32.dll: cannot open shared file: no such file or directory."
@MaitePerez - Please upgrade to .NET 2.1 or newer. 2.0 is EOL and no longer supported. I'm sure you will got more support once you upgrade to a supported version.
@MichaelSimons Thank you so much for the replay.
I'm actually using net core 2.1 and net and net standar 2.0, sorry for the confusi贸n.
For alpine dotnet runtime, add additional repository
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && apk update && apk add --no-cache libgdiplus
Quick confirmation here. libgdiplus wasn't enough, I needed to use
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
to have it working on microsoft/dotnet:2.1.2-aspnetcore-runtime.
I added the install of libgdiplus, but I still get this runtime error. Am I missing something from my Dockerfile?
I'm on windows but docker set to linux containers.
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ["projectx/projectx.csproj", "projectx/"]
RUN dotnet restore "projectx/projectx.csproj"
COPY . .
WORKDIR "/src/projectx"
RUN dotnet build "projectx.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "projectx.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "projectx.dll"]
RUN apk add libgdiplus-dev fontconfig ttf-dejavu --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
For microsoft/dotnet:3.0-runtime-alpine
I added the install of libgdiplus, but I still get this runtime error. Am I missing something from my Dockerfile?
I'm on windows but docker set to linux containers.
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM microsoft/dotnet:2.2-sdk AS build # install System.Drawing native dependencies RUN apt-get update \ && apt-get install -y --allow-unauthenticated \ libc6-dev \ libgdiplus \ libx11-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /src COPY ["projectx/projectx.csproj", "projectx/"] RUN dotnet restore "projectx/projectx.csproj" COPY . . WORKDIR "/src/projectx" RUN dotnet build "projectx.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "projectx.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "projectx.dll"]
Make sure you install it in your runtime and not in your dotnet build.
e.g. here is my solution
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime-stage
WORKDIR /app
#######################################################
# Add dependencies for Gdip in the runtime application. System.Drawing.
#######################################################
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list && \
echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list && \
echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libgdiplus \
# libc6-dev \
# libgdiplus \
# libx11-dev \
&& rm -rf /var/lib/apt/lists/*
############################### END of Gdip dependencies
@jbdhacf Thanks!
That was the issue. Moving the install up to under
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base solved my issue
With microsoft/dotnet:2.2-aspnetcore-runtime still have similar problems.
FROM microsoft/dotnet:2.2-aspnetcore-runtime
EXPOSE $PORT
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
COPY bin/Release/netcoreapp2.2/publish/ /app/
WORKDIR /app
CMD /bin/bash -c "dotnet ea.Api.dll"
Unable to load shared library 'user32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libuser32.dll: cannot open shared object file: No such file or directory
With microsoft/dotnet:2.2-aspnetcore-runtime still have similar problems.
FROM microsoft/dotnet:2.2-aspnetcore-runtime EXPOSE $PORT # install System.Drawing native dependencies RUN apt-get update \ && apt-get install -y --allow-unauthenticated \ libc6-dev \ libgdiplus \ libx11-dev \ && rm -rf /var/lib/apt/lists/* COPY bin/Release/netcoreapp2.2/publish/ /app/ WORKDIR /app CMD /bin/bash -c "dotnet ea.Api.dll"Unable to load shared library 'user32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libuser32.dll: cannot open shared object file: No such file or directory
Were you able to move past this issue?
For folks as noobish about Docker as I am, make sure that these changes (which worked for me - thanks!) get put in the LAST layer of your dockerfile. The provided code shows that clearly in the FROM statement, but I didn't notice that at first and added this stuff in my build layer, which of course was useless.
can I use it with alpine docker images? seemed there's libgdiplus support for alpine https://pkgs.alpinelinux.org/packages?name=libgdiplus&branch=edge
-------------- update ---------------------
absolutely yes, you can specific the repository url
for example:
apk add libgdiplus --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
you get the complete Dockerfile I used here https://github.com/WeihanLi/ActivityReservation/blob/dev/Dockerfile
Hi!
I have the same problema but when i insall all the libgdiplus libreary then i have another error about Kernel32, im using dotnet core 2.0, is there any suggestion?"Unable to load shared library 'kernel32.dll or one of its dependencies. In order to help diagnose problems, consider setting the LD_DEBUG enviroment variable: kernel32.dll: cannot open shared file: no such file or directory."
Same problem here @MaitePerez. Have you managed to find the solution?
Hi!
I have the same problema but when i insall all the libgdiplus libreary then i have another error about Kernel32, im using dotnet core 2.0, is there any suggestion?"Unable to load shared library 'kernel32.dll or one of its dependencies. In order to help diagnose problems, consider setting the LD_DEBUG enviroment variable: kernel32.dll: cannot open shared file: no such file or directory."
@MaitePerez I found the solution to my case, see if it's useful to you. I was using a library to convert html to pdf that depends on windows to run (even being .net core compatible). Here is the link of the issue: https://github.com/selectpdf/selectpdf-free-html-to-pdf-converter/issues/2
The solution naturally was change to a lib that don't rely on windows dlls.
This line plus the next 10 lines gave us what we needed to use a Bitmap
Me works this way:
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so
# install native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends \
apt-utils \
libgdiplus \
libx11-6 \
libxext6 \
libxrender1 \
&& curl -o /usr/lib/libwkhtmltox.so \
--location \
https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so
WORKDIR /app
COPY --from=build-env /app/out ./
Thanks @JetstreamRoySprowl
@Dangelo123 May I ask which PDF lib you did end up with?
@jbdhacf Thanks!
That was the issue. Moving the install up to under
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS basesolved my issue
This solution solved my issue. Thanks a lot and a beer to @jbdhacf
Back in dotnetcore 2.2, I had to use this process to add all of the necessary libraries to my container so that it would work with system.drawing. This may have to be updated for 3.1. I'm actually working on this today for 3.1 so ill provide any updated instructions as I find them:
1) docker pull ubuntu
2) docker run -t ubuntu:latest /bin/bash -> to open a container shell ->
3) apt-get update apt
4) apt-get install wget
5) wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
6) dpkg -i packages-microsoft-prod.deb
7) apt-get install apt-transport-https
8) apt-get update
9) apt-get install dotnet-sdk-2.2 <---- this will need to change for sure
10) apt-get install libgdiplus
11) cd /usr/lib
12) ln -s libgdiplus.so gdiplus.dll
13) apt-get install libc6-dev libx11-dev
14) rm -rf /var/lib/apt/lists/*
The steps for adding the required components to use System.Drawing is also documented in the Using the System.Drawing.Common Package in a Docker Container snippet.
@Dangelo123 May I ask which PDF lib you did end up with?
What library did you end up using?
@Denny966 I gave up finding a decent netcore PDF library
Ended up, satisfied, using https://github.com/thecodingmachine/gotenberg
okay after reading and trying all these different apt-gets and whatnot, to get system.drawing.common to work in blazor server side with .NET Core 3.1 it was as simple as this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
RUN apt-get update && apt-get install -y libgdiplus
WORKDIR /app
Hi!
I have the same problema but when i insall all the libgdiplus libreary then i have another error about Kernel32, im using dotnet core 2.0, is there any suggestion?
"Unable to load shared library 'kernel32.dll or one of its dependencies. In order to help diagnose problems, consider setting the LD_DEBUG enviroment variable: kernel32.dll: cannot open shared file: no such file or directory."@MaitePerez I found the solution to my case, see if it's useful to you. I was using a library to convert html to pdf that depends on windows to run (even being .net core compatible). Here is the link of the issue: selectpdf/selectpdf-free-html-to-pdf-converter#2
The solution naturally was change to a lib that don't rely on windows dlls.
So which library you ended up picking?
It happens the same for NET 5 with _Google.Cloud.Firestore_ nuget package in a mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim docker image.
The fix is still to add the native lib libc6-dev:
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
&& rm -rf /var/lib/apt/lists/*
Most helpful comment
@sddev-dotnet - Hmm, sounds like the underlying issue was an intermittent issue with the apt feed you are using to pull from. Try it again on your Windows machine. I just tried a Bitmap sample app and everything worked as expected from both a Windows and Linux Docker host. FYI - I was using the microsoft/dotnet:2.1-sdk image which is based on Debian Stretch.
One tip regarding the pattern used to install the apt packages. Make sure you cleanup the apt cache within your Dockerfile as this bloats the resulting image. It is a Docker best practice.