简体   繁体   中英

How to install GDAL Library in Docker Python image?

I'm using python3.7-slim-buster docker image for my django project. Now I want to use Geo features of django. But it seems I have to install GDAL. So, I do RUN apt-get install gdal and it raises exception "E: Unable to locate package gdal-bin". Here is my docker file:


FROM python:3.7-slim-buster

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# DB vars
ENV DB_USER_NAME ${DB_USER_NAME}
ENV DB_NAME ${DB_NAME}
ENV DB_HOST ${DB_HOST}
ENV DB_PORT ${DB_PORT}
ENV DB_PASSWORD ${DB_PASSWORD}

ENV DJANGO_SECRET_KEY ${DJANGO_SECRET_KEY}

RUN apt-get install -y gdal-bin python-gdal python3-gdal

RUN ["adduser", "${USER_NAME}", "--disabled-password", "--ingroup", "www-data", "--quiet"]

USER ${USER_NAME}

ADD ${PROJECT_NAME}/ /home/${USER_NAME}/${PROJECT_NAME}
WORKDIR /home/${USER_NAME}/${PROJECT_NAME}

ENV PATH="/home/${USER_NAME}/.local/bin:\${PATH}:/usr/local/python3/bin"

RUN pip install --user -r requirements.txt

CMD python manage.py runserver 0.0.0.0:9000
#CMD gunicorn ${PROJECT_NAME}.wsgi:application --bind 0.0.0.0:8000
EXPOSE 8000

you need to do the following:

RUN apt-get update
RUN apt-get install -y software-properties-common && apt-get update
RUN apt-get install -y python3.7-dev
RUN  add-apt-repository ppa:ubuntugis/ppa &&  apt-get update
RUN apt-get install -y gdal-bin libgdal-dev
ARG CPLUS_INCLUDE_PATH=/usr/include/gdal
ARG C_INCLUDE_PATH=/usr/include/gdal
RUN pip install GDAL

That's because your image doesn't have repository which contain gdal-bin package. So you have to add repository (you can see the guideline here ) and install it:

RUN add-apt-repository ppa:ubuntugis/ppa && apt-get update && apt-get install -y gdal-bin python-gdal python3-gdal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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