docker setting up gdal for django

Viewed 1380

I'm setting a django project and trying to use docker with it. It has a dependency to gdal likely from using postgis.

This is the docker file

FROM python:3

ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY . /code/
RUN pip install -r requirements.txt

and the requirements file

Django==2.1.5
psycopg2==2.7.6.1
gdal==2.2.3

when it reaches gdal it throws this error

FileNotFoundError: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'

however this is something I've already got working locally

(pw) sam@sam-Lenovo-G51-35:~/code/pw$ gdal-config --version
2.2.3

I did try to see if I can make it setup gdal-config using run by editing the docker file to this

FROM python:3

ENV PYTHONUNBUFFERED 1
RUN mkdir /code
RUN apt-get install libgdal-dev
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal
WORKDIR /code
COPY . /code/
RUN pip install -r requirements.txt

based on the nearest match for error to possible solution but it throws this error

Step 4/9 : RUN apt-get install libgdal-dev
---> Running in 8e5e71369e4a
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package libgdal-dev
1 Answers

You forgot apt-get update in your Dockerfile before running apt-get install.

Consider

Dockerfile

...
RUN apt-get update && apt-get install --yes libgdal-dev
...
Related