wkhtmltopdf with php:8-fpm-alpine
Asked Answered
C

3

9

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.

Cream answered 6/12, 2021 at 12:52 Comment(0)
G
8

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
Government answered 7/12, 2021 at 11:28 Comment(1)
Unfortunately, since PHP 8.2 images for alpine 3.14 are not generated github.com/docker-library/php/tree/master/8.2Mond
C
12

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
Counterword answered 5/8, 2022 at 9:26 Comment(1)
I have tried that with php:8.2-fpm-alpine3.17, installation goes well, but usage throw exceptions. There is error with mix of versions and dependencies. Some of them get from 3.14 repo, other from 3.17.Mond
G
8

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
Government answered 7/12, 2021 at 11:28 Comment(1)
Unfortunately, since PHP 8.2 images for alpine 3.14 are not generated github.com/docker-library/php/tree/master/8.2Mond
M
6

My modern approach using surnet/alpine-wkhtmltopdf image

Goals:

  • Use the newest alpine (3.17 here)
  • Use the newest php (8.2 here)
  • Have wkhtmltopdf anyway
  • Do not include legacy repositories

Dockerfile:

FROM surnet/alpine-wkhtmltopdf:3.16.2-0.12.6-full as wkhtmltopdf
FROM php:8.2-fpm-alpine3.17 AS app


# wkhtmltopdf install dependencies
RUN apk add --no-cache \
        libstdc++ \
        libx11 \
        libxrender \
        libxext \
        libssl1.1 \
        ca-certificates \
        fontconfig \
        freetype \
        ttf-droid \
        ttf-freefont \
        ttf-liberation \
        # more fonts
        ;

# wkhtmltopdf copy bins from ext image
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/libwkhtmltox.so /bin/


# install php extensions, apache/nginx etc.

  1. You can control version of alpine-wkhtmltopdf image
  2. You can control version of php and alpine
  3. You can download more fonts if you need

Partially based on manual

Mond answered 12/12, 2022 at 15:8 Comment(1)
For those looking to use wkhtmltopdf with PHP8.2, this approach works!Emmaemmalee

© 2022 - 2024 — McMap. All rights reserved.