如何使用 dockerfile 在 gcp 应用程序引擎上安装 poppler?

Kac*_*rek 3 google-app-engine poppler docker google-cloud-platform

我正在部署一个使用 pdf2image 到 gcp 应用程序引擎的应用程序。当我想测试它时,我得到了一个错误:

pdf2image.exceptions.PDFInfoNotInstalledError:无法获取页数。poppler 是否已安装并位于 PATH 中?

我找到了这篇文章并将 dockerfile 添加到我的项目中,如下所示:

FROM gcr.io/google-appengine/python

# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN apt-get install poppler-utils
RUN virtualenv -p python3.7 /env

# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

# Add the application source code.
ADD . /app

# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD gunicorn -b :$PORT main:app
Run Code Online (Sandbox Code Playgroud)

我还更改了 app.yaml 文件:

runtime: custom
env: flex
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试部署应用程序时,我得到:

步骤 2/9:运行 apt-get install poppler-utils

---> 在 db1e5bebd0a8 中运行

正在阅读包装清单...

构建依赖树...

正在读取状态信息...

E:无法找到包 poppler-utils

命令“/bin/sh -c apt-get install poppler-utils”返回非零代码:100

错误

错误:构建步骤 0“gcr.io/cloud-builders/docker”失败:退出状态 100

我还尝试了 python-poppler 而不是 poppler-utils 并得到了相同的错误。

我发现这篇关于安装 poppler 的文章,现在我想知道我是否可以在 dockerfile 中执行此操作,我以前没有使用过 docker,这是我的第一个 dockerfile。

Joa*_*oël 13

您应该在安装之前获取软件包apt-get update,否则软件包管理器将找不到它并抛出此错误。

此外,安装包将要求您通过输入Y/n提示来确认安装,而在 Dockerfile 中则无法执行此操作。为了避免这种情况,请将该标志添加-y到命令中apt-get install

将此更改添加到您的 Dockerfile 中将如下所示:

FROM gcr.io/google-appengine/python

RUN apt-get update
RUN apt-get install poppler-utils -y
RUN virtualenv -p python3.7 /env

# Rest of your build steps...
Run Code Online (Sandbox Code Playgroud)