我正在将一个使用 pdf2image 的应用部署到 gcp 应用引擎。当我想测试它时,我得到了一个错误:
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
我找到了这个 post并将 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
现在,当我尝试部署应用时,我得到:
Step 2/9 : RUN apt-get install poppler-utils
---> Running in db1e5bebd0a8
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package poppler-utils
The command '/bin/sh -c apt-get install poppler-utils' returned a non-zero code: 100
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 100
我也尝试了 python-poppler 而不是 poppler-utils 并得到了同样的错误。
我找到了这个 post about installing 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...
关于docker - 如何使用 dockerfile 在 gcp 应用引擎上安装 poppler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55216164/