Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work inside docker #53

Closed
Preetham-P opened this issue Sep 17, 2018 · 15 comments
Closed

Doesn't work inside docker #53

Preetham-P opened this issue Sep 17, 2018 · 15 comments

Comments

@Preetham-P
Copy link

Hi,
I would appreciate if the above same code is once tested in docker and if it works pls upload the steps. I get unable to shared library every time.
"One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibwkhtmltox: cannot open shared object file: No such file or directory)"
but the libraries exist at the current directory.

@jincod
Copy link

jincod commented Sep 21, 2018

Hi @Preetham-P

This helped me #34 (comment)

I'm using alpine image. My Dockerfile:

...
RUN apk --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ add\
    libgdiplus\
    xvfb\
    fontconfig\
    wkhtmltopdf\
    libc6-compat\
    openssl\
    libssl1.0\
    && rm  -rf /tmp/* /var/cache/apk/*
RUN wget --quiet https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so -O libwkhtmltox.so\
    && wget --quiet https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.dll -O libwkhtmltox.dll

@csepanda
Copy link

csepanda commented Oct 8, 2018

Your library might be placed in application directory, but it's possible that this directory is not listed in LD_LIBRARY_PATH environment variable. Try to add your directory PATH into this variable.
export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH

@Isuama
Copy link

Isuama commented Nov 5, 2018

I think you have missed out few packages. This worked for me.

FROM alpine:3.7

RUN apk add --no-cache curl
RUN curl -o /usr/lib/libwkhtmltox.so --location https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

RUN apk add libgdiplus
wkhtmltopdf
--no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted

RUN apk add xvfb
libc6-compat
fontconfig
libx11
libxext
libxrender
libstdc++
freetype
libssl1.0
--no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ --allow-untrusted

@bchhun
Copy link

bchhun commented Apr 19, 2019

I also resolved this issue within a container;

Here's the relevant part of my dockerfile:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
# <wkhtmltopdf>
ENV PATH=/app;$PATH
RUN apt-get update
RUN apt-get install wget fontconfig libfreetype6 libx11-6 libxcb1 libxext6 libxrender1 xfonts-75dpi xfonts-base libjpeg62-turbo -y

RUN wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u11_amd64.deb
RUN dpkg -i libssl1.0.0_1.0.1t-1+deb8u11_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_amd64.deb
RUN dpkg -i libpng12-0_1.2.50-2+deb8u3_amd64.deb

RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.jessie_amd64.deb
RUN dpkg -i wkhtmltox_0.12.5-1.jessie_amd64.deb

RUN cp /usr/local/bin/wkhtmlto* /usr/bin/
# </wkhtmltopdf>
# ...

And I also transfered the libwkhtmltox.dll/libwkhtmltox.so/libwkhtmltox.dylib files within the container's workdir with this within the *.csproj file:

     <ItemGroup>
        <None Update="libwkhtmltox.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
        <None Update="libwkhtmltox.dylib">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
        <None Update="libwkhtmltox.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
    </ItemGroup>

@marvpipe
Copy link

marvpipe commented May 6, 2019

@bchhun Hi,
can you show me your complete dockerfile please?

Im always getting "An error occurred whilte attempting to build Docker image."

@AmbroiseCouissin
Copy link

AmbroiseCouissin commented Jul 31, 2019

Footers don't work on the current version of wkhtmltopdf doesn't work on alpine. We needed to use surnet's version (https://github.com/Surnet/docker-wkhtmltopdf):


FROM surnet/alpine-wkhtmltopdf:3.8-0.12.5-full as wkhtmltopdf
FROM microsoft/dotnet:2.2.0-aspnetcore-runtime-alpine AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.2.100-sdk-alpine AS build
WORKDIR /build
COPY . .

RUN dotnet build -c Release
RUN dotnet test --no-build -c Release

FROM build AS publish
RUN dotnet publish src/Application/Application.csproj -c Release -o /app

FROM base AS final
WORKDIR /app

# Install dependencies for wkhtmltopdf
RUN apk add --no-cache \
  libstdc++ \
  libx11 \
  libxrender \
  libxext \
  libssl1.0 \
  ca-certificates \
  fontconfig \
  freetype \
  ttf-dejavu \
  ttf-droid \
  ttf-freefont \
  ttf-liberation \
  ttf-ubuntu-font-family \
  font-noto \
  font-adobe-100dpi 

RUN apk add --no-cache --virtual .build-deps msttcorefonts-installer \
  && update-ms-fonts \
  && fc-cache -f \
  && apk del .build-deps


RUN apk --no-cache --repository http://nl.alpinelinux.org/alpine/edge/testing --allow-untrusted add wqy-zenhei

# Clean up when done
RUN rm -rf /tmp/*

# Copy wkhtmltopdf files from docker-wkhtmltopdf image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /usr/bin/
COPY --from=wkhtmltopdf /bin/libwkhtmltox* /usr/lib/
COPY --from=publish /app .

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

@bryht
Copy link

bryht commented Sep 25, 2019

I fixed mine by using this.

FROM microsoft/dotnet:2.2-aspnetcore-runtime

RUN apt-get update

RUN apt-get install wget libgdiplus -y

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

/app is where your app running.

@rasert
Copy link

rasert commented Oct 1, 2019

I think you have missed out few packages. This worked for me.

FROM alpine:3.7

RUN apk add --no-cache curl
RUN curl -o /usr/lib/libwkhtmltox.so --location https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

RUN apk add libgdiplus
wkhtmltopdf
--no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted

RUN apk add xvfb
libc6-compat
fontconfig
libx11
libxext
libxrender
libstdc++
freetype
libssl1.0
--no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ --allow-untrusted

Not working on Alpine 3.9 from Asp.Net Core runtime.

@bchhun
Copy link

bchhun commented Oct 9, 2019

@bchhun Hi,
can you show me your complete dockerfile please?

Im always getting "An error occurred whilte attempting to build Docker image."

@marvpipe You should probably show me yours :) My dockerfile is almost all there in my comment up there

@Preetham-P
Copy link
Author

I also resolved this issue within a container;

Here's the relevant part of my dockerfile:

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
# <wkhtmltopdf>
ENV PATH=/app;$PATH
RUN apt-get update
RUN apt-get install wget fontconfig libfreetype6 libx11-6 libxcb1 libxext6 libxrender1 xfonts-75dpi xfonts-base libjpeg62-turbo -y

RUN wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u11_amd64.deb
RUN dpkg -i libssl1.0.0_1.0.1t-1+deb8u11_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_amd64.deb
RUN dpkg -i libpng12-0_1.2.50-2+deb8u3_amd64.deb

RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.jessie_amd64.deb
RUN dpkg -i wkhtmltox_0.12.5-1.jessie_amd64.deb

RUN cp /usr/local/bin/wkhtmlto* /usr/bin/
# </wkhtmltopdf>
# ...

And I also transfered the libwkhtmltox.dll/libwkhtmltox.so/libwkhtmltox.dylib files within the container's workdir with this within the *.csproj file:

     <ItemGroup>
        <None Update="libwkhtmltox.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
        <None Update="libwkhtmltox.dylib">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
        <None Update="libwkhtmltox.so">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        </None>
    </ItemGroup>

This solved it. Thanks

@parasmm
Copy link

parasmm commented Dec 18, 2020

Recently we faced the same issue in our application while moving from windows based AWS EC2 instances to containerized application using Alpine Linux. However, after going through all the packages referenced in above comments and all the good suggestions given, we noticed one difference.

Initially we were using Alpine Linux version 3.12 where as these solutions used Alpine Linux version 3.7. We have not tried with any other version of Alpine but downgraded (3.7) version worked for us.

In addition, once this was resolved our generated PDF showed incorrect formatting for Double.ToString("C0") gave ¤ character instead of $. Which pointed us to issues with culture info settings on Alpine Linux with dotnet.

Alpine Linux has no cultures installed and .Net Core 2.0 introduced a Globalization Invariant Mode, which when enabled, makes all cultures behave like invariant culture.

On Alpine Linux, as the package for culture info is not installed, the Globalization Invariant mode is set to false.

So to fix this, we had to install the required packages for culture info, disable globalization invariant environment variable -

# Install required package for culture 
RUN apk add --no-cache icu-libs

# Disable global invariant environment variable
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

Additionally, in our start-up class we specified our default culture as below -

var cultureInfo = new CultureInfo("en-US");

CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

Reference Articles -
Using DinkToPDF on Alpine Linux
.NET Core, Docker, and Cultures - Solving a culture issue porting a .NET Core app from Windows to Linux

@Unlink
Copy link

Unlink commented Jan 14, 2021

https://github.com/Surnet/docker-wkhtmltopdf

This works to me with latest alpine image

mcr.microsoft.com/dotnet/aspnet:5.0-alpine

FROM surnet/alpine-wkhtmltopdf:3.9-0.12.5-full as wkhtmltopdf
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

...build part of process

FROM build AS publish
RUN dotnet publish "MyProject.csproj" -c Release -o /app/publish

FROM base AS final

###### wkhtmltopdf part
RUN apk add --no-cache \
  libstdc++ \
  libx11 \
  libxrender \
  libxext \
  libssl1.1 \
  ca-certificates \
  fontconfig \
  freetype \
  ttf-dejavu \
  ttf-droid \
  ttf-freefont \
  ttf-liberation \
  ttf-ubuntu-font-family \
&& apk add --no-cache --virtual .build-deps \
  msttcorefonts-installer \
\
# Install microsoft fonts
&& update-ms-fonts \
&& fc-cache -f \
\
# Clean up when done
&& rm -rf /tmp/* \
&& apk del .build-deps

# Copy wkhtmltopdf files from docker-wkhtmltopdf image to app folder
COPY --from=wkhtmltopdf /bin/libwkhtmltox.so /app/libwkhtmltox.so

WORKDIR /app
COPY --from=publish /app/publish .
... rest of Dockerfile

@hadoan
Copy link

hadoan commented May 5, 2021

I fixed mine by using this.

FROM microsoft/dotnet:2.2-aspnetcore-runtime

RUN apt-get update

RUN apt-get install wget libgdiplus -y

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

/app is where your app running.

Thank you, it worked in my project!

@Orbis25
Copy link

Orbis25 commented Jul 14, 2022

I fixed mine by using this.

FROM microsoft/dotnet:2.2-aspnetcore-runtime

RUN apt-get update

RUN apt-get install wget libgdiplus -y

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

/app is where your app running.

Working for me.. 14/07/2022

@PoomBE
Copy link

PoomBE commented Jan 25, 2024

I fixed mine by using this.

FROM microsoft/dotnet:2.2-aspnetcore-runtime

RUN apt-get update

RUN apt-get install wget libgdiplus -y

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dll

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.dylib

RUN wget -P /app https://github.com/rdvojmoc/DinkToPdf/raw/master/v0.12.4/64%20bit/libwkhtmltox.so

/app is where your app running.

Not Working for me 25/1/2024 So sad
I Use Macbook or Error System.AggregateException: One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems

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

No branches or pull requests