简体   繁体   English

App Engine Flexible - Docker 文件无法安装 GDAL

[英]App Engine Flexible - Docker file fails to install GDAL

I am trying to deploy a Django application to App Engine Flexible Environment.我正在尝试将 Django 应用程序部署到 App Engine 柔性环境。 My dockerfile is failing to install GDAL.我的 dockerfile 无法安装 GDAL。

This is the error message that i get when running gcloud app deploy :这是我在运行gcloud app deploy时收到的错误消息:

  File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 42, in <module>
    % '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
[2020-04-24 16:12:26 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-04-24 16:12:26 +0000] [1] [INFO] Shutting down: Master
[2020-04-24 16:12:26 +0000] [1] [INFO] Reason: Worker failed to boot.

This is my dockerfile:这是我的 dockerfile:

FROM ubuntu:bionic

RUN apt-get update && apt-get install -y \
  binutils \
  gdal-bin \
  python3-gdal \
  ibgdal-dev \
  libproj-dev

# 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 virtualenv /env -p python3.7



# 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.
RUN pip install -r requirements.txt

# Add the application source code.
ADD . /


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

and this is my app.yaml:这是我的 app.yaml:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  # You can also specify 2 for Python 2.7
  python_version: 3.7

I am aware that I am asking a very similar question that being answered here , but the askers own solution doesn't seem to be working.我知道我在问一个非常相似的问题,在这里得到回答,但提问者自己的解决方案似乎没有用。

To me, it seems as if you are missing a proper gdal installation.对我来说,好像您缺少正确的gdal安装。 Indeed it can be bit tricky to install but on ubuntu (also with docker ), I generally have good experiences installing it from ubuntugis .确实安装起来有点棘手,但在ubuntu (也有docker )上,我通常有从ubuntugis安装它的良好经验。

Here's an example:这是一个例子:

FROM ubuntu:bionic

RUN apt-get update && apt-get install -y \
    software-properties-common \
    python3 \
    python3-dev \
    python3-pip \
  && rm -rf /var/lib/apt/lists/*

RUN add-apt-repository ppa:ubuntugis/ppa

RUN apt-get update && apt-get install -y \
    gdal-bin=2.4.2+dfsg-1~bionic0 \
    python3-gdal \
  && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y libpq-dev \
  && rm -rf /var/lib/apt/lists/*
...

I think the issue is in the Docker file.我认为问题出在Docker文件中。 You have the following:你有以下内容:

...
RUN apt-get update && apt-get install -y \
  binutils \
  gdal-bin \
  python3-gdal \
  ibgdal-dev \
  libproj-dev
....

And I think the lib's name is libgdal-dev instead of ibgdal-dev而且我认为 lib 的名称是libgdal-dev而不是ibgdal-dev

I would second Val's answer to use the 'ubuntugis' PPA and have more recent GDAL etc. libraries available.我会赞同 Val 的回答,使用“ubuntugis”PPA 并提供更新的 GDAL 等库。 At least that did the trick for me.至少那对我有用。 I should add that I went off the base GAE flex image (which is based on Ubuntu 16.04 LTS xenial) so that GAE's health checks work as intended.我应该补充一点,我离开了基本的 GAE flex 图像(基于 Ubuntu 16.04 LTS xenial),以便 GAE 的健康检查按预期工作。 They can be hard to debug too.它们也很难调试。

You also need to use GAE's custom/flex environment in your app.yaml (assuming your project is called "my-app" so check where wsgi.py is located):您还需要在您的app.yaml中使用 GAE 的 custom/flex 环境(假设您的项目名为“my-app”,因此请检查wsgi.py所在的位置):

runtime: custom
env: flex
entrypoint: gunicorn -b :$PORT my-app.wsgi

runtime_config:
    python_version: 3

Give this Dockerfile a try:试试这个 Dockerfile:

FROM gcr.io/google-appengine/python
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive

RUN apt -y update && apt -y upgrade\
    && apt-get install -y software-properties-common \
    && add-apt-repository -y ppa:ubuntugis/ppa \
    && apt -y update && apt -y upgrade\
    && apt-get -y install \
    gdal-bin \
    libgdal-dev \
    python3-gdal  \ 
    && apt-get autoremove -y \
    && apt-get autoclean -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN virtualenv /env -p python3.7
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

ADD requirements.txt /app/requirements.txt
RUN python3 -m pip install -r /app/requirements.txt 
ADD . /app/
WORKDIR /app
CMD gunicorn -b :$PORT my-app.wsgi

Note that you mention in one of your comments above to add the requirements.txt to your container but you actually don't do that in the Dockerfile.请注意,您在上面的一条评论中提到将requirements.txt添加到您的容器中,但实际上您并没有在 Dockerfile 中这样做。

Python 3.7 comes with the GAE base image, but if you want to go for 3.8 see the Dockerfile describe here Python 3.7 带有 GAE 基本映像,但如果您想要 go 用于 3.8,请参阅此处的 Dockerfile 描述

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

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