Home > database >  Installation of wkhtmltopdf fails in docker environment
Installation of wkhtmltopdf fails in docker environment

Time:12-11

I'm trying to install wkhtmltopdf in my docker environment. what ever I try it fails. my current Dockerfile looks like this

FROM python:3.8.5

...
...

# Installation of dependencies Abhängigkeiten
RUN apt-get update
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt-get install -y ghostscript -f
RUN apt-get install -y fontforge -f
RUN apt-get install -y cabextract -f
RUN wget https://gist.github.com/maxwelleite/10774746/raw/ttf-vista-fonts-installer.sh -q -O - | bash

RUN apt-get install -y wget
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
RUN apt-get install -f
RUN dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb

and this ends with the following error codes

Step 13/32 : RUN dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
 ---> Running in 49712db15630
Selecting previously unselected package wkhtmltox.
(Reading database ... 26470 files and directories currently installed.)
Preparing to unpack wkhtmltox_0.12.6-1.bionic_amd64.deb ...
Unpacking wkhtmltox (1:0.12.6-1.bionic) ...
dpkg: dependency problems prevent configuration of wkhtmltox:
 wkhtmltox depends on libjpeg-turbo8; however:
  Package libjpeg-turbo8 is not installed.
 wkhtmltox depends on xfonts-75dpi; however:
  Package xfonts-75dpi is not installed.
 wkhtmltox depends on xfonts-base; however:
  Package xfonts-base is not installed.
dpkg: error processing package wkhtmltox (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 wkhtmltox
The command '/bin/sh -c dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb' returned a non-zero code: 1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

i tried with all different available wkhtmltopdf installations and none of it worked. Anyone can help?

CodePudding user response:

You could use apt-get install to fix up missing dependencies. Example:

FROM python:3.8.5
RUN apt-get update
RUN apt-get install --no-install-recommends -y \
 apt-utils ghostscript fontforge cabextract \
 wget
ARG WKHTML2PDF_VERSION='0.12.6-1'
RUN export VERSION_CODENAME=$(. /etc/os-release; echo $VERSION_CODENAME) \
 && wget https://github.com/wkhtmltopdf/packaging/releases/download/${WKHTML2PDF_VERSION}/wkhtmltox_${WKHTML2PDF_VERSION}.${VERSION_CODENAME}_amd64.deb -O wkhtmltox.deb
RUN dpkg -i wkhtmltox.deb || apt-get install -f -y

CodePudding user response:

I see a couple of problems here. First, you are trying to install an Ubuntu Bionic Beaver version of WKHTMLTOPDF on a Debian Buster os. So, I would recommend using the correct release.

Second, you are clearly missing some dependencies as stated in the error message. So you should install those.

Lastly, this is purely optional, but I would recommend grouping your install commands in one layer (one Docker command here RUN), this will help make your final image smaller.

Here is the content of a Dockerfile that would build.

FROM python:3.8.5

RUN set -e; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        apt-utils \
        ghostscript \
        fontforge \
        cabextract \
        wget \
        libjpeg-turbo8 \
        xfonts-75dpi \
        xfonts-base; \
    wget https://gist.github.com/maxwelleite/10774746/raw/ttf-vista-fonts-installer.sh -q -O - | bash; \
    wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb ; \
    dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb; \
    rm -rf rm -rf /var/lib/apt/lists/*

Cheers

  • Related