Home:ALL Converter>How to install GDAL Library in Docker Python image?

How to install GDAL Library in Docker Python image?

Ask Time:2019-10-17T21:24:39         Author:Alihaydar Gubatov

Json Formatter

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

Author:Alihaydar Gubatov,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58433776/how-to-install-gdal-library-in-docker-python-image
LinPy :

you need to do the following:\n\nRUN apt-get update\nRUN apt-get install -y software-properties-common && apt-get update\nRUN apt-get install -y python3.7-dev\nRUN add-apt-repository ppa:ubuntugis/ppa && apt-get update\nRUN apt-get install -y gdal-bin libgdal-dev\nARG CPLUS_INCLUDE_PATH=/usr/include/gdal\nARG C_INCLUDE_PATH=/usr/include/gdal\nRUN pip install GDAL\n",
2019-10-17T13:29:58
M.wol :

If you can use other base image, here is one with gdal installed:\nFROM osgeo/gdal:ubuntu-small-3.2.0",
2021-07-13T08:05:35
yy