Search code examples
dockerdocker-composedockerfile

wkhtmltopdf not working in Sylius project


First of all, i installed Sylius using the following command :

git clone [email protected]:Sylius/Sylius-Standard.git sylius && cd sylius && make init

I tried to add the wkhtmltopdf binary file to the Sylius Docker container following this tutorial: https://blog.bitexpert.de/blog/sylius_docker_alpine_wkhtmltopdf I modified the existing compose.override.yml as follows:

php:
    build: ./Docker/
    user: ${DOCKER_USER:-1000:1000}

And for the Dockerfile, I did the following instructions :

FROM surnet/alpine-wkhtmltopdf:3.16.2-0.12.6-full as wkhtmltopdf

FROM ghcr.io/sylius/sylius-php:8.2-fixuid-xdebug-alpine AS base

USER root
# persistent / runtime deps
RUN apk add --no-cache \
        acl \
        file \
        gettext \
        unzip \
        libstdc++ \
        libx11 \
        libxrender \
        libxext \
        libssl3 \
        openssl \
        ca-certificates \
        fontconfig \
        freetype \
        ttf-droid \
        ttf-freefont \
        ttf-liberation \
    ;

RUN ln -s /lib/libssl.so.1.1.1 /usr/lib/libssl.so.1.1 && \
    ln -s /lib/libcrypto.so.1.1.1 /usr/lib/libcrypto.so.1.1

# Copy needed wkhtmltopdf files from wkhtmltopdf image
COPY --from=wkhtmltopdf /bin/wkhtmltoimage /bin/wkhtmltopdf /bin/libwkhtmltox* /usr/local/bin/

However, when I ran the docker-compose build, I couldn't find the wkhtmltopdf file in /usr/local/bin/.


Solution

  • Finally, I found a solution to my problem: there needs to be consistency between the versions of surnet/alpine-wkhtmltopdf and ghcr.io/sylius/sylius-php

    So, Here's the Dockerfile code that works well for me :

    FROM surnet/alpine-wkhtmltopdf:3.20.0-0.12.6-full as wkhtmltopdf
    
    FROM ghcr.io/sylius/sylius-php:8.2-fixuid-xdebug-alpine AS sylius_php
    
    USER root
    # install wkhtmltopdf runtime dependencies
    RUN apk add --no-cache \
        libstdc++ \
        libx11 \
        libxrender \
        libxext \
        libssl3 \
        ca-certificates \
        fontconfig \
        freetype \
        ttf-droid \
        ttf-freefont \
        ttf-liberation
    
    # Copy needed wkhtmltopdf files from wkhtmltopdf image
    COPY --from=wkhtmltopdf /bin/wkhtmltoimage /bin/wkhtmltopdf /bin/libwkhtmltox* /usr/local/bin/