skip to Main Content

I’m trying to setup GDAL in Docker to support a Python back-end web server using Flask. After running docker compose up -d I’m receiving the following error:

Could not find gdal-config. Make sure you have installed the GDAL native library and development headers.

I tried a solution from a similar question on setting up Docker and GDAL for Django: How to add GDAL in docker to run with an alpine Docker image but this did not resolve the error:

RUN apk --no-cache add ca-certificates tzdata
RUN apk add --no-cache –repository 
http://dl-cdn.alpinelinux.org/alpine/edge/testing gdal

My Dockerfile:

FROM python:3.10-alpine

COPY requirements.txt /
RUN pip install -r requirements.txt

COPY app /app/

ENV FLASK_APP=/app
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_DEBUG=0

CMD ["gunicorn", "-b", "0.0.0.0:1111", "app:app"]

My docker-compose:

services:
   backend:
      build:
         context: ./backend
         dockerfile: Dockerfile
      ports:
          - '1111:1111'

2

Answers


  1. Chosen as BEST ANSWER

    After clarifying the requirement more, it turns out that installing GDAL through the Dockerfile was not necessary in my case as I just needed to install it on my local Ubuntu environment first before I ran the Docker Compose to start up the back-end web server.


  2. You can install the gdal and gdal-dev packages via apk and define the necessary paths so that the python libraries can find them.

    FROM python:3.12-alpine
    
    RUN apk upgrade --update
    RUN apk add --no-cache build-base gcc gdal gdal-dev zlib
    
    RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
    RUN export C_INCLUDE_PATH=/usr/include/gdal
    RUN export LDFLAGS="-L/usr/local/opt/zlib/lib"
    RUN export CPPFLAGS="-I/usr/local/opt/zlib/include"
    
    WORKDIR /app
    COPY . /app
    
    RUN pip install --no-cache-dir -r requirements.txt
    
    # ...
    

    Since the alpine package sources provide version 3.9.1 of gdal, it is necessary to use a compatible version under python. So this line is required within the requirements.

    gdal==3.9.1
    # ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search