如何使用DockerFile在GCP应用引擎上安装Poppler



我正在部署一个使用PDF2Image到GCP App Engine的应用程序。当我想测试它时,我会有一个错误:

pdf2image.exceptions.pdfinfonotinstallederror:无法获得页面计数。是否安装了流行音乐?

我找到了这篇文章,并在我的项目中添加了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

我也更改了app.yaml文件:

runtime: custom
env: flex

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

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

--->在db1e5bebd0a8中运行

阅读包列表...

建立依赖树...

阅读状态信息...

e:无法找到包装Popppler-Utils

命令'/bin/sh -c apt-get安装poppler-utils'返回一个非零 代码:100

错误

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

我还尝试了Python-poppler而不是Poppler-Utils,并遇到了相同的错误。

我找到了有关安装Poppler的文章,现在我想知道我是否可以在Dockerfile中这样做,我以前从未与Docker一起工作,这是我的第一个Dockerfile。

您应该在安装它之前使用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...

最新更新