Dockerized Dotnet Core 2.1 throws Gdip exception when using Select.HtmlToPdf.NetCore - docker

I am using Select.HtmlToPdf.NetCore(18.3.0) to convert Html to pdf in Dotnetcore 2.1. It is perfectly working in local environment but when hosted with Docker it throws an error saying,
{"fileName":"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\n at Interop.Libdl.dlopen(String fileName,
Int32 flag)\n at
System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()\n at
System.Drawing.SafeNativeMethods.Gdip..cctor()\n --- End of inner
exception stack trace ---\n at
System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr&
fontCollection)\n at SelectPdf.Lib.ᡜ..ctor()\n at
SelectPdf.Lib.៞..ctor()\n at SelectPdf.Lib.៞..ctor(ᡏ A_0, ᠝ A_1)\n
at SelectPdf.HtmlToPdf.ᜁ(String A_0, String A_1, String A_2, String
A_3, Boolean A_4)\n at SelectPdf.HtmlToPdf.ConvertHtmlString(String
htmlString)
I have tried by adding these set of lines in Dockerfile, but still having the same error.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
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
EXPOSE 80

I know It is an old question but I encountered this problem lately and I would like to share with my solution.
Select.HtmlToPdf.NetCore do not work on linux
Just do not. If you already have generated string with html I would advise you to find this nuget: Haukcode.DinkToPdf
To find some tutorials just google DinkToPdf. Haukcode is just updated and more docker friendly version.
some dockerfile stuff:
FROM microsoft/aspnetcore:2.0.0 as Base
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN apt-get install -y libc6-dev
RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll
...
I hope it will help someone :)

this worked for me.
I'm running a Debian server, using System.Drawing.Common 4.7.0
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*

You need to install libc6-dev in your Docker container. You can install libc6-dev by running the following command:
RUN apt-get install -y libc6-dev
Let me know how that goes.

I was facing the same problem too using iTextSharp 5.5.13.1 and the way I've solved is combine #Frederik Carlier's solution in my Dockerfile:
RUN apt-get update && apt-get -y install libxml2 libgdiplus libc6-dev
After that, i've restarted Rancher Container and Rancher User Stack and it works fine.
(Runtime used: FROM microsoft/dotnet:2.2-aspnetcore-runtime)

Related

laravel-with-docker-example project fails to build

I am trying to run below project with docker.
https://github.com/kyleferguson/laravel-with-docker-example
which has the below docker file.
FROM php:7-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
When i run the "docker-compose up" after running the "composer install".
I get below errors.
executor failed running [/bin/sh -c apt-get update && apt-get install
-y libmcrypt-dev mariadb-client && docker-php-ext-install mcrypt pdo_mysql]: exit code: 1 ERROR: Service 'app' failed to build
Any idea on how to fix this?
Note:
I already tried replacing mariadb-client with mysql-client and default-my-client, still the same issue.
You have a couple problems here, which is why switching to mariadb didn't work on its own.
One way to make it more clear what the problem is, is to bash into a container created from your base image and run the commands manually.
docker run -it php:7-fpm bash
From there if you run each install individually you'll see where you are failing:
# apt-get install -y mysql-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql-client
Either add a repo that provides mysql, or use mariadb.
# docker-php-ext-install mcrypt
error: /usr/src/php/ext/mcrypt does not exist
mcrypt was removed in php 7.2 so you'll need to use pecl to install it, if you really need it.
Unless you're running a very old version of Laravel, you shouldn't need mcrypt.

Docker build stops on software-properties-common when run with `apt update`

I have 2 dockerfiles:
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y \
software-properties-common \
python3
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get update && apt-get install -y \
python3
The thing is: when I run the first of them (with docker build) the build process hangs on:
The software-properties-common package is asking me about the geographical area - I cannot provide any input, it is not allowed when building images, I suppose.
However, when I build the second dockerfile, this problem does not occur. I'm curious - why is that?
Add the following line in your Dockerfile and build again.
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
I found that running
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
before setting DEBIAN_FRONTEND=noninteractive worked for me. (You'd want to replace the bit after zoneinfo with whatever is applicable for you.)
If you need it to be set dynamically, [this answer] (https://stackoverflow.com/a/63153978/1995015) suggests calling out to a website that can provide that.

Install Java runtime in Debian based docker image

I am trying to install the java runtime in a Debian based docker image (mcr.microsoft.com/dotnet/core/sdk:3.1-buster). According to various howtos this should be possible by running
RUN apt update
RUN apt-get install openjdk-11-jre
The latter command comes back with
E: Unable to locate package openjdk-11-jre
However according to https://packages.debian.org/buster/openjdk-11-jre the package does exist. What am I doing wrong?
Unsure from which image your are pulling. I used slim, Dockerfile.
from debian:buster-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-11-jre
# Prints installed java version, just for checking
RUN java --version
NOTE: If you don't run the mkdir -p /usr/share/man/man1 /usr/share/man/man2 you'll run into dependency problems with ca-certificates, openjdk-11-jre-headless etc. I've been using this fix provided by community, haven't really checked the permanent fix.

Cannot install php, apache and postgres on ubuntu base image in dockerfile

I started studying docker recently and wanted to install php, apache and postgres in a ubuntu base image. But cannot run it after build.
Here is my Dockerfile
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -qq -y install curl
RUN apt-get -y install apache2
RUN apt-get -y install php7.0
RUN apt-get -y install libapache2-mod-php7.0
RUN apt-get -y install php7.0-mysql
RUN apt-get -y install php7.0-pgsql
RUN apt-get -y install php7.0-gd
RUN apt-get -y install php-pear
RUN apt-get -y install php7.0-curl
COPY . /var/www/html
EXPOSE 80
Can you please help me?
Thanks.
there are several issues here. First of all, I have the impression that you're mixing up docker and virtual machines. For this I suggest to go and read what are the differences.
Concerning your question, the problem is that the base image (ubuntu:16.04) has CMD bash (or something similar, I really didn't check) and therefore php is not considered.
In order to start apache, you should append the following:
CMD . /etc/apache2/envvars && /usr/sbin/apache2ctl -DFOREGROUND
Anyway, I'd suggest you give a check to the php official image.

Building Go Application using confluent-kafka-go on Linux

I am trying to create a docker image with my go application. The application (which was developed on MacOS) depends on confluent-kafka-go which in turn depends on librdkafka-dev which I install in the Docker image like so:
FROM golang:1.1
RUN apt-get update
RUN apt-get -y install librdkafka-dev
VOLUME /workspace
WORKDIR /workspace/src/my/app/folder
ENTRYPOINT ["/bin/sh", "-c"]
I am getting the following error:
my/app/folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka
../folder/vendor/github.com/confluentinc/confluent-kafka-go/kafka/00version.go:44:2: error: #error "confluent-kafka-go requires librdkafka v0.11.5 or later. Install the latest version of librdkafka from the Confluent repositories, see http://docs.confluent.io/current/installation.html"
As far as I understand the latest version is installed.
How can I fix it?
I had a similar issue a few weeks ago. IIRC confluent-kafka-go requires a recent version of librdkafka-dev, which simply was not yet released to alpine or others.
I was able to find it for ubuntu though, so my solution (which was more involved than I hoped for, but it worked), was to start from clean ubuntu, install librdkafka-dev, install Go version that I want and compile inside docker.
Here's how it looks:
FROM ubuntu
# Install the C lib for kafka
RUN apt-get update
RUN apt-get install -y --no-install-recommends apt-utils wget gnupg software-properties-common
RUN apt-get install -y apt-transport-https ca-certificates
RUN wget -qO - https://packages.confluent.io/deb/5.1/archive.key | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/5.1 stable main"
RUN apt-get update
RUN apt-get install -y librdkafka-dev
# Install Go
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get install -y golang-1.11-go
# build the library
WORKDIR /go/src/gitlab.appsflyer.com/rantav/kafka-mirror-tester
COPY *.go ./
COPY // the rest of your go files. You may copy recursive if you want
COPY vendor vendor
RUN GOPATH=/go GOOS=linux /usr/lib/go-1.11/bin/go build -a -o main .
EXPOSE 8000
ENTRYPOINT ["./main"]
You can specify a version of package to be installed in apt-get command.
e.g
apt-get install librdkafka-dev=0.11.6~1confluent5.0.1-1
If that doesn't work then I think the apt sources doesn't have version 0.11.5 of librdkafka.
You can add a repository with the right version of librdkafka in /etc/apt/sources.list as described here:
https://docs.confluent.io/current/installation/installing_cp/deb-ubuntu.html#systemd-ubuntu-debian-install

Resources