无法在 Docker 映像 php:8.0-fpm-alpine 中使用 wkhtmltopdf
我正在使用 php:8.0-fpm-alpine3.14
Docker 映像,其中有一个 Sylius 项目,并且我想使用 wkhtmltopdf
,因此我按照以下链接操作:
- https://sasablagojevic.com/setting-up-wkhtmltopdf-on-docker-alpine-linux
- https://github.com/wkhtmltopdf/packaging/issues/2#issuecomment-725962861
所以我目前有这个 Docker 映像:
FROM php:8.0-fpm-alpine3.14 AS sylius_php
# persistent / runtime deps
RUN apk add --no-cache \
acl \
file \
gettext \
git \
mariadb-client \
;
ARG APCU_VERSION=5.1.17
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
coreutils \
freetype-dev \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libtool \
libwebp-dev \
libzip-dev \
mariadb-dev \
; \
\
docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype; \
docker-php-ext-configure zip --with-zip; \
docker-php-ext-install -j$(nproc) \
exif \
gd \
intl \
pdo \
pdo_mysql \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .sylius-phpexts-rundeps $runDeps; \
\
apk del .build-deps
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/php-cli.ini /usr/local/etc/php/php-cli.ini
RUN apk --update --no-cache add \
wkhtmltopdf \
libgcc \
libstdc++ \
musl \
qt5-qtbase \
qt5-qtbase-x11 \
qt5-qtsvg \
qt5-qtwebkit \
ttf-freefont \
ttf-dejavu \
ttf-droid \
ttf-liberation \
xvfb \
fontconfig
# Add openssl dependencies for wkhtmltopdf
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories && \
apk add --no-cache libcrypto1.0 libssl1.0
RUN ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf;
RUN chmod +x /usr/local/bin/wkhtmltopdf;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN set -eux; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"
WORKDIR /srv/sylius
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
wkhtmltopdf
的安装没问题,但我得到当我运行 bin/console sylius:install -s plus
命令时出现以下错误:
我不明白为什么会收到该错误等如何解决这个问题。
谢谢
I am using php:8.0-fpm-alpine3.14
Docker image in which I have a Sylius project and I would like use wkhtmltopdf
, so I followed these links:
- https://sasablagojevic.com/setting-up-wkhtmltopdf-on-docker-alpine-linux
- https://github.com/wkhtmltopdf/packaging/issues/2#issuecomment-725962861
So I currently have this Docker image:
FROM php:8.0-fpm-alpine3.14 AS sylius_php
# persistent / runtime deps
RUN apk add --no-cache \
acl \
file \
gettext \
git \
mariadb-client \
;
ARG APCU_VERSION=5.1.17
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
coreutils \
freetype-dev \
icu-dev \
libjpeg-turbo-dev \
libpng-dev \
libtool \
libwebp-dev \
libzip-dev \
mariadb-dev \
; \
\
docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype; \
docker-php-ext-configure zip --with-zip; \
docker-php-ext-install -j$(nproc) \
exif \
gd \
intl \
pdo \
pdo_mysql \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .sylius-phpexts-rundeps $runDeps; \
\
apk del .build-deps
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/php-cli.ini /usr/local/etc/php/php-cli.ini
RUN apk --update --no-cache add \
wkhtmltopdf \
libgcc \
libstdc++ \
musl \
qt5-qtbase \
qt5-qtbase-x11 \
qt5-qtsvg \
qt5-qtwebkit \
ttf-freefont \
ttf-dejavu \
ttf-droid \
ttf-liberation \
xvfb \
fontconfig
# Add openssl dependencies for wkhtmltopdf
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories && \
apk add --no-cache libcrypto1.0 libssl1.0
RUN ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf;
RUN chmod +x /usr/local/bin/wkhtmltopdf;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN set -eux; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"
WORKDIR /srv/sylius
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
The installation of wkhtmltopdf
is ok but I get the following error when I run bin/console sylius:install -s plus
command:
I don't understand why I get that error et how to fix that.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据wkhtmltopdf FAQ,它不应该在 alpine 发行版中正常工作。
无论如何,当尝试构建 pdf 时,HTML 中的
sylius-logo.png
图像似乎无法访问,这表明重定向状态。According to wkhtmltopdf FAQ, it is not supposed to work properly in the alpine distro.
Anyway, the
sylius-logo.png
image from the HTML seems not to be accessible when trying to build the pdf, indicating a redirect status.