wkhtmltopdf with php:8-fpm-alpine

Viewed 2401

I have an existing php:8-fpm-alpine Dockerfile, and i need to add WKHTMLTOPDF package. Is that even possible. I tried using following dockerfile, but i get following error log:

Dockerfile...

FROM php:8-fpm-alpine
...
RUN apk add xvfb libfontconfig wkhtmltopdf

error:

ERROR [ 8/13] RUN apk add --no-cache wkhtmltopdf                                                                                                   2.1s

[ 8/13] RUN apk add --no-cache wkhtmltopdf:
#12 0.567 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
#12 1.097 fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
#12 2.001 ERROR: unable to select packages:
#12 2.034   wkhtmltopdf (no such package):
#12 2.034     required by: world[wkhtmltopdf]

executor failed running [/bin/sh -c apk add --no-cache wkhtmltopdf]: exit code: 1
ERROR: Service 'php' failed to build : Build failed

I tried including contents from following repository, but i think its way too much work for 1 package, and it breaks in build process: https://github.com/alloylab/Docker-Alpine-wkhtmltopdf

Any help would be appreciated.

2 Answers

I faced a similar problem with php:7.4-fpm-alpine image.

It seems like wkhtmltopdf is missing in Alpine v.3.15, but it is available in v.3.14.

Try to change

FROM php:8-fpm-alpine

to

FROM php:8-fpm-alpine3.14

I had the same problem when trying to update to php:8.1.9-fpm-alpine3.16

To get this to work I added a link to the community 3.14 repository for wkhtmltopdf. It turned out it had some dependencies from the main repository also :

ERROR: unable to select packages:
  so:libicui18n.so.67 (no such package):
    required by: qt5-qtwebkit-5.212.0_alpha4-r14[so:libicui18n.so.67]
  so:libicuuc.so.67 (no such package):
    required by: qt5-qtwebkit-5.212.0_alpha4-r14[so:libicuuc.so.67]

So you need to add that aswell

# Install packages not yet updated for the current alpine version TODO remove when no longer needed
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/community' >> /etc/apk/repositories
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/main' >> /etc/apk/repositories
RUN apk add --no-cache wkhtmltopdf
Related