GeoDjango在基于docker python alpine的映像上找不到gdal

问题描述 投票:0回答:1

我正在使用gdal创建一个geodjango容器(基于Python高山官方图像)。启动容器时,出现以下错误:

>>> from django.contrib.gis import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/li...
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

我的图像包含以下gdal库:

# find / -name libgdal*
/usr/lib/libgdal.so.20
/usr/lib/libgdal.so.20.5.0
/usr/lib/libgdal.a
/usr/lib/libgdal.so

GDAL_LIBRARY_PATH='usr/lib/libgdal.so.20'添加到我的django设置无法解决此问题。

我的Dockerfile,基于官方python3高山图像。

FROM python:alpine

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR /usr/src/dbchiro

COPY requirements.txt /usr/src/dbchiro

# GeoDjango Dependencies

RUN  echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \
     && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
     && echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories  \
     && apk add --virtual .build-deps zlib-dev jpeg-dev gdal-dev musl-dev postgresql-dev\
      alpine-sdk libffi-dev jpeg-dev python-dev zlib-dev libffi gcc \ 
     && apk add --no-cache postgresql-libs geos gdal postgresql-client libpq proj nginx \ 
     && python3 -m pip install --upgrade pip --no-cache-dir \
     && python3 -m pip install -r requirements.txt --no-cache-dir \
     && python3 -m pip install gunicorn --no-cache-dir \
     && apk --purge del .build-deps


COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh

COPY . /usr/src/dbchiro

VOLUME ["/app","/app/media"]

WORKDIR /app

EXPOSE 80

ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

CMD ["/bin/sh"]

docker-entrypoint

#!/bin/sh

export DBHOST=${DBHOST:-db}
...

shopt -s dotglob nullglob
mv /usr/src/dbchiro/* /app/

ls /app

cp -a /app/dbchiro/settings/configuration/config.py.sample /app/dbchiro/settings/configuration/config.py

sed -i "s/dbHost/${DBHOST}/g" /app/dbchiro/settings/configuration/config.py
...

until pg_isready -h $DBHOST -p $DBPORT
do
  echo "Awaiting Database container"
  sleep 1
done
sleep 2

cd /app

export DJANGO_SETTINGS_MODULE=dbchiro.settings.$SETTINGS

python -m manage makemigrations  accounts core blog dicts geodata management sights
python -m manage migrate  
python -m manage collectstatic --noinput 

cp /app/static/img/logo_site.png.sample /app/static/img/logo_site.png

#nginx Conf

cp /app/dbchiro/settings/configuration/nginx_dbchiro.conf.sample /etc/nginx/conf.d/dbchiro.conf
rm /etc/nginx/sites-enabled/*
sed -i "s/pathToApp/app/g" /etc/nginx/conf.d/dbchiro.conf
/etc/init.d/nginx restart

gunicorn -b 127.0.0.1:8000 dbchiro.wsgi

要求

arrow==0.15.2
backports.csv==1.0.7
colorlog==4.0.2
defusedxml==0.6.0
Django==2.2.5
django-autocomplete-light==3.4.1
django-ckeditor==5.7.1
django-crispy-forms==1.7.2
django-debug-toolbar==2.0
django-extensions==2.2.1
django-filter==2.2.0
django-geojson==2.12.0
django-js-asset==1.2.2
django-leaflet==0.24.0
django-nested-admin==3.2.4
django-tables2==2.1.1
et-xmlfile==1.0.1
jdcal==1.4.1
odfpy==1.4.0
openpyxl==3.0.0
Pillow==6.1.0
psycopg2-binary==2.8.3
python-dateutil==2.8.0
python-monkey-business==1.0.0
pytz==2019.2
PyYAML==5.1.2
six==1.12.0
sqlparse==0.3.0
tablib==0.13.0
xlrd==1.2.0
xlwt==1.3.0

请提供一些帮助,完整的项目在这里https://framagit.org/fred.perso/dbchiroweb/tree/docker

django dockerfile gdal geodjango alpine
1个回答
0
投票

我在安装Linux virtualenv时遇到了同样的问题,我设法使用官方文档使其正常工作:

GDAL是一个出色的开源地理空间库,它支持读取大多数矢量和栅格空间数据格式。目前,GeoDjango仅支持GDAL的矢量数据功能[2]。在构建GDAL之前,应先安装GEOS和PROJ.4。首先下载最新的GDAL发行版本并解压缩存档: wget https://download.osgeo.org/gdal/X.Y.Z/gdal-X.Y.Z.tar.gz tar xzf gdal-X.Y.Z.tar.gz cd gdal-X.Y.Z

配置,制作和安装: ./configure make # Go get some coffee, this takes a while. sudo make install cd ..

您可以参考Django文档以获取更多详细信息:Django Documentation

© www.soinside.com 2019 - 2024. All rights reserved.