简体   繁体   English

Laradock 如何使用 apk 而不是 apt-get 添加包

[英]Laradock how to add package using apk instead of apt-get

I am using Laradock to deploy a Laravel app.我正在使用 Laradock 部署 Laravel 应用程序。

I am facing a problem with generating a PDF file to attach it in an email in a queued job .我在生成 PDF 文件以将其附加到排队作业的电子邮件中时遇到问题。 The pending jobs are handle by the php-worker container.待处理的作业由php-worker容器处理。

The problem is that when you want to attach a PDF to an email, which is queued (therefore, handled by the php-worker container) I get the following error:问题是,当您想将 PDF 附加到排队的电子邮件(因此,由php-worker容器处理)时,我收到以下错误:

"sh: /usr/local/bin/wkhtmltopdf: not found “sh:/usr/local/bin/wkhtmltopdf:未找到

which means that the wkhtmltopdf is not installed in the php-worker container.这意味着wkhtmltopdf未安装在php-worker容器中。

So, taking a look at either the php-fpm or workspace Dockerfile, I can see how to install the wkhtmltopdf like so:因此,查看php-fpm工作区Dockerfile,我可以看到如何安装wkhtmltopdf ,如下所示:

#####################################
# wkhtmltopdf:
#####################################

USER root

ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
    apt-get install -yqq \
      libxrender1 \
      libfontconfig1 \
      libx11-dev \
      libjpeg62 \
      libxtst6 \
      fontconfig \
      libjpeg62-turbo \
      xfonts-base \
      xfonts-75dpi \
      wget \
    && wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb \
    && dpkg -i wkhtmltox_0.12.6-1.stretch_amd64.deb \
    && apt -f install \
;fi

If I copy that installation code into the php-worker container, I get the following error如果我将该安装代码复制到php-worker容器中,我会收到以下错误

/bin/sh: apt-get: not found /bin/sh: apt-get: 未找到

So, searching further, it seems the php-worker container is Alpine based , and probably needs apk add because of Alpine.因此,进一步搜索,似乎php-worker 容器是基于 Alpine 的,并且由于 Alpine 可能需要apk add

I have tried the following:我尝试了以下方法:

#####################################
# wkhtmltopdf:
#####################################

USER root

ARG INSTALL_WKHTMLTOPDF=false

RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
    apk add --no-cache \
      libxrender1 \
      libfontconfig1 \
      libx11-dev \
      libjpeg62 \
      libxtst6 \
      fontconfig \
      libjpeg62-turbo \
      xfonts-base \
      xfonts-75dpi \
      wget \
      wkhtmltopdf \
;fi

But I haven't got luck.但我没有运气。

ERROR: unable to select packages: wkhtmltopdf (no such package): required by: world[wkhtmltopdf]错误:无法选择包:wkhtmltopdf(没有这样的包):需要:world[wkhtmltopdf]

I have been editing the Dockerfile based on this link and this is what I've modified so far: Dockerfile我一直在根据这个链接编辑 Dockerfile ,这是我到目前为止修改的内容: Dockerfile

#
#--------------------------------------------------------------------------
# Image Setup
#--------------------------------------------------------------------------
#

ARG LARADOCK_PHP_VERSION
FROM php:${LARADOCK_PHP_VERSION}-alpine3.14

LABEL maintainer="Mahmoud Zalt <mahmoud@zalt.me>"

ARG LARADOCK_PHP_VERSION

# If you're in China, or you need to change sources, will be set CHANGE_SOURCE to true in .env.

ARG CHANGE_SOURCE=false
RUN if [ ${CHANGE_SOURCE} = true ]; then \
  # Change application source from dl-cdn.alpinelinux.org to aliyun source
  sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories \
  ;fi

RUN apk --update add wget \
  curl \
  git \
  build-base \
  libmcrypt-dev \
  libxml2-dev \
  linux-headers \
  pcre-dev \
  zlib-dev \
  autoconf \
  cyrus-sasl-dev \
  libgsasl-dev \
  oniguruma-dev \
  libressl \
  libressl-dev \
  supervisor

# ...................

#####################################
# wkhtmltopdf:
#####################################

USER root

ARG INSTALL_WKHTMLTOPDF=false

RUN set -xe; \
if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
# Install dependencies for wkhtmltopdf
  apk add --update --no-cache --wait 10 \
  && apk --no-cache upgrade \
  && apk add --no-cache \
  bash \
  libstdc++ \
  libx11 \
  libxrender \
  libxext \
  libssl1.1 \
  ca-certificates \
  fontconfig \
  freetype \
  ttf-dejavu \
  ttf-droid \
  ttf-freefont \
  ttf-liberation \
  xvfb \
  #libQt5WebKit \ This throws error. Commented out.
  #libQt5WebKitWidgets \ This throws error. Commented out.
  #ttf-ubuntu-font-family \ This throws error. Commented out.
  && apk add --update --no-cache --virtual .build-deps \
  msttcorefonts-installer \
  vim \
\
# Install microsoft fonts
&& update-ms-fonts \
&& fc-cache -f \
\
# Clean up when done
&& rm -rf /tmp/* \
&& apk del .build-deps \

   && wget http://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/wkhtmltopdf-0.12.6-r0.apk \
   && apk add --allow-untrusted wkhtmltopdf-0.12.6-r0.apk \
   && echo 'WKHTMLTOPDF INSTALLED?' \
   && which wkhtmltopdf \
#   && ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf \
   && cp /usr/bin/wkhtmltoimage /usr/local/bin/ \
   && cp /usr/bin/wkhtmltopdf /usr/local/bin/  \
   && chmod +x /usr/local/bin/wkhtmltoimage \
   && chmod +x /usr/local/bin/wkhtmltopdf \
   && echo 'wkhtmltopdf version: ' \
   && /usr/local/bin/wkhtmltopdf -V \
   && echo 'whoami & permissions'  \
   && whoami \
   && ls -lah /usr/bin/ \
   && ls -lah /usr/local/bin/ \

;fi


#
#-----------------------------
# Set PHP memory_limit to infinity
#-------------------------------
#

RUN echo 'set php memory to -1:' \
&& sed -i 's/memory_limit = .*/memory_limit=-1 /' /usr/local/etc/php/php.ini-production  \
&& sed -i 's/memory_limit = .*/memory_limit=-1 /' /usr/local/etc/php/php.ini-development \
&& cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini


# ...

Finally, the wkhtmltopdf seems to be installed:最后,似乎安装了wkhtmltopdf

+ apk add --allow-untrusted wkhtmltopdf-0.12.6-r0.apk
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/43) Installing icu-libs (67.1-r2)
(2/43) Installing libpcre2-16 (10.36-r0)
(3/43) Installing qt5-qtbase (5.15.3_git20210406-r0)
(4/43) Installing hicolor-icon-theme (0.17-r1)
(5/43) Installing wayland-libs-server (1.19.0-r0)
(6/43) Installing mesa-gbm (21.1.2-r0)
(7/43) Installing wayland-libs-client (1.19.0-r0)
(8/43) Installing qt5-qtdeclarative (5.15.3_git20210531-r0)
(9/43) Installing libxcomposite (0.4.5-r0)
(10/43) Installing wayland-libs-cursor (1.19.0-r0)
(11/43) Installing wayland-libs-egl (1.19.0-r0)
(12/43) Installing libxkbcommon (1.2.1-r0)
(13/43) Installing qt5-qtwayland (5.15.3_git20210510-r0)
(14/43) Installing mesa-egl (21.1.2-r0)
(15/43) Installing libevdev (1.11.0-r1)
(16/43) Installing mtdev (1.1.6-r0)
(17/43) Installing eudev-libs (3.2.10-r0)
(18/43) Installing libinput-libs (1.18.0-r0)
(19/43) Installing xcb-util-wm (0.4.1-r1)
(20/43) Installing xcb-util (0.4.0-r3)
(21/43) Installing xcb-util-image (0.4.0-r1)
(22/43) Installing xcb-util-keysyms (0.4.0-r1)
(23/43) Installing xcb-util-renderutil (0.3.9-r1)
(24/43) Installing libxkbcommon-x11 (1.2.1-r0)
(25/43) Installing qt5-qtbase-x11 (5.15.3_git20210406-r0)
(26/43) Installing qt5-qtsvg (5.15.3_git20200406-r0)
(27/43) Installing qt5-qtlocation (5.15.3_git20201109-r0)
(28/43) Installing qt5-qtsensors (5.15.3_git20201028-r1)
(29/43) Installing qt5-qtwebchannel (5.15.3_git20201028-r0)
(30/43) Installing libxv (1.0.11-r2)
(31/43) Installing alsa-lib (1.2.5-r2)
(32/43) Installing cdparanoia-libs (10.2-r9)
(33/43) Installing gstreamer (1.18.4-r0)
(34/43) Installing libogg (1.3.5-r0)
(35/43) Installing opus (1.3.1-r1)
(36/43) Installing orc (0.4.32-r0)
(37/43) Installing libtheora (1.1.1-r16)
(38/43) Installing libvorbis (1.3.7-r0)
(39/43) Installing gst-plugins-base (1.18.4-r0)
(40/43) Installing hyphen (2.8.8-r1)
(41/43) Installing libxslt (1.1.35-r0)
(42/43) Installing qt5-qtwebkit (5.212.0_alpha4-r14)
(43/43) Installing wkhtmltopdf (0.12.6-r0)
Executing busybox-1.33.1-r7.trigger
OK: 877 MiB in 254 packages
WKHTMLTOPDF INSTALLED?
+ echo 'WKHTMLTOPDF INSTALLED?'
+ which wkhtmltopdf
/usr/bin/wkhtmltopdf
+ cp /usr/bin/wkhtmltoimage /usr/local/bin/
+ cp /usr/bin/wkhtmltopdf /usr/local/bin/
+ chmod +x /usr/local/bin/wkhtmltoimage
+ chmod +x /usr/local/bin/wkhtmltopdf
+ echo 'wkhtmltopdf version: '
+ /usr/local/bin/wkhtmltopdf -V
wkhtmltopdf version: 
wkhtmltopdf 0.12.6

+ echo 'whoami & permissions'
+ whoami
whoami & permissions
root
+ ls -lah /usr/bin/
-rwxr-xr-x    1 root     root         979 Jun  1  2021 supervisorctl
-rwxr-xr-x    1 root     root         975 Jun  1  2021 supervisord
-rwxr-xr-x    1 root     root      114.1K Jun 11  2020 wkhtmltoimage
-rwxr-xr-x    1 root     root      162.1K Jun 11  2020 wkhtmltopdf
+ ls -lah /usr/local/bin/
-rwxr-xr-x    1 root     root      114.1K May 25 16:37 wkhtmltoimage
-rwxr-xr-x    1 root     root      162.1K May 25 16:37 wkhtmltopdf

Step 82/86 : COPY supervisord.conf /etc/supervisord.conf
 ---> de059f102569
Step 83/86 : ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c",  "/etc/supervisord.conf"]

BUT when I try to execute the container to verify that the wkhtmltopdf is indeed installed,但是当我尝试执行容器以验证确实安装了wkhtmltopdf时,

❯ docker container exec php-worker /usr/local/bin/wkhtmltopdf -V                                                                                                        ─╯
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "/usr/local/bin/wkhtmltopdf": stat /usr/local/bin/wkhtmltopdf: no such file or directory: unknown

turns out that it's not been installed!原来它没有安装! And therefore, I get the exact same error in my application:因此,我在我的应用程序中得到了完全相同的错误:

"sh: /usr/local/bin/wkhtmltopdf: not found “sh:/usr/local/bin/wkhtmltopdf:未找到

And, on the other hand, for example, the supervisor does work:另一方面,例如,主管确实工作:

❯ docker container exec php-worker supervisorctl                                                                                                                        ─╯
laravel-scheduler:laravel-scheduler_00   RUNNING   pid 52576, uptime 18:27:24
laravel-worker:laravel-worker_00         RUNNING   pid 52577, uptime 18:27:24

supervisor> 

Does anybody know how to install wkhtmltopdf in Alpine Dockerfile for real?有人知道如何在 Alpine Dockerfile 中真正安装 wkhtmltopdf 吗?

The PHP images you're using are built on Alpine 3.15;您使用的 PHP 映像是基于 Alpine 3.15 构建的; it looks like wkhtmltopdf isn't package in that version of Alpine:看起来wkhtmltopdf不是该版本的 Alpine 中的软件包:

$ docker run --rm alpine:3.15 sh -c 'apk add --update wkhtmltopdf'
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
  wkhtmltopdf (no such package):
    required by: world[wkhtmltopdf]

It looks like wkhtmltopdf is only available in 3.14 and earlier (I checked 3.14 and 3.13):看起来wkhtmltopdf仅在 3.14 及更早版本中可用(我检查了 3.14 和 3.13):

$ docker run --rm alpine:3.14 sh -c 'apk add --update wkhtmltopdf'
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/103) Installing dbus-libs (1.12.20-r2)
(2/103) Installing libgcc (10.3.1_git20210424-r2)
[...]
(103/103) Installing wkhtmltopdf (0.12.6-r0)
Executing busybox-1.33.1-r7.trigger
OK: 196 MiB in 117 packages

This is noted in the release notes for 3.15 , which say:这在3.15 的发行说明中有所说明,其中说:

QtWebKit was removed due to lack of upstream support由于缺乏上游支持,QtWebKit 被删除

qt5-qtwebkit, kdewebkit, wkhtmltopdf, and py3-pdfkit have been removed due to known vulnerabilities and lack of upstream support for qtwebkit.由于已知漏洞和缺乏对 qtwebkit 的上游支持,qt5-qtwebkit、kdewebkit、wkhtmltopdf 和 py3-pdfkit 已被删除。 Other programs have been adjusted to use qt5-qtwebengine where appropriate.其他程序已调整为在适当的情况下使用 qt5-qtwebengine。 The most direct replacement for wkhtmltopdf is weasyprint, which is available in the Alpine Linux community repository. wkhtmltopdf 最直接的替代品是 weasyprint,它可以在 Alpine Linux 社区存储库中找到。 puppeteer and pandoc are also options, depending on your needs. puppeteer 和 pandoc 也是选项,具体取决于您的需要。 See #12888 for more information.有关详细信息,请参阅#12888。

You could dry building your own PHP base image on top of an older Alpine release using the upstream Dockerfile , or you could try starting with the vanilla alpine:3.14 image and installing php using apk .您可以使用上游 Dockerfile在较旧的 Alpine 版本之上干构建自己的 PHP 基础映像,或者您可以尝试从 vanilla alpine:3.14映像开始并使用apk安装 php。

Or just stick with an Ubuntu-based image, which still packages wkhtmltopdf .或者只是坚持使用基于 Ubuntu 的图像,它仍然打包wkhtmltopdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM