如何使用 dockerfile 在 gcp 应用引擎上安装 poppler?
How to install poppler on gcp app engine using dockerfile?
我正在将一个使用 pdf2image 的应用部署到 gcp 应用引擎。当我想测试它时,我得到了一个错误:
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
我找到了这个 并将 docker 文件添加到我的项目中,这是它的样子:
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 现在我想知道我是否可以在 docker 文件中执行此操作,我之前没有使用过 docker,这是我的第一个 docker文件.
你应该在安装前用 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...
我正在将一个使用 pdf2image 的应用部署到 gcp 应用引擎。当我想测试它时,我得到了一个错误:
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
我找到了这个
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 现在我想知道我是否可以在 docker 文件中执行此操作,我之前没有使用过 docker,这是我的第一个 docker文件.
你应该在安装前用 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...