Search code examples
phpdockerwkhtmltopdf

Docker - install wkhtmltopdf - error updating from 0.12.4 to 0.12.6


I have a dockerfile which successfully installs wkhtmltopdf v0.12.4 but I need to update this to a newer version (0.12.6) as it doesn't seem to be compatible with some other upgrades I've made.

Here's the code that works (albeit incompatible)

FROM php:7.3.31-apache

...

RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz --no-check-certificate

RUN tar -xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

RUN cp wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

RUN cp wkhtmltox/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage

RUN rm -rf wkhtmltox wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

RUN touch .wkhtmltopdf

...

And here's the code that's not working...

...

RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/archive/refs/tags/0.12.6.tar.gz --no-check-certificate

RUN tar -xvf wkhtmltopdf-0.12.6.tar.gz

RUN cp wkhtmltopdf-0.12.6/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

RUN cp wkhtmltopdf-0.12.6/bin/wkhtmltoimage /usr/local/bin/wkhtmltoimage

RUN rm -rf wkhtmltox wkhtmltopdf-0.12.6.tar.gz

RUN touch .wkhtmltopdf

...

And here's the error message I'm getting...

 > [ 7/26] RUN cp wkhtmltopdf-0.12.6/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf:
#10 0.573 cp: cannot stat 'wkhtmltopdf-0.12.6/bin/wkhtmltopdf': No such file or directory
------
executor failed running [/bin/sh -c cp wkhtmltopdf-0.12.6/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf]: exit code: 1

Solution

  • Based on the comments, the url that you use to download the package 0.12.6 doesn't include the precompiled binary, only the source code. One way to get it would be to try to compile it yourself during the docker image build. Another, easier way would be to use one of the deb packages from 0.12.6 r1 (as suggested here), for example this deb package should be what you need to install wkhtmltopdf/wkhtmltoimage into php:7.3.31-apache: wkhtmltox_0.12.6-1.buster_amd64.deb.

    It requires couple of packages to be installed, here is a full list of commands that would download and install it:

    apt update
    
    apt install -y wget fontconfig fontconfig-config fonts-dejavu-core libbsd0 \
    libfontconfig1 libfontenc1 libfreetype6 libjpeg62-turbo libmd0 libpng16-16 \
    libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxrender1 sensible-utils \
    ucf x11-common xfonts-75dpi xfonts-base xfonts-encodings xfonts-utils
    
    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
    

    Here is to verify the versions:

    root@0c6cf969f847:/var/www/html# wkhtmltopdf -V
    wkhtmltopdf 0.12.6 (with patched qt)
    
    root@0c6cf969f847:/var/www/html# wkhtmltoimage -V
    wkhtmltoimage 0.12.6 (with patched qt)
    

    Here are the locations of the binaries installed from deb, in case you need to adjust your process:

    root@0c6cf969f847:/var/www/html# which wkhtmltopdf
    /usr/local/bin/wkhtmltopdf
    
    root@0c6cf969f847:/var/www/html# which wkhtmltoimage
    /usr/local/bin/wkhtmltoimage