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
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.
You can install the gdal and gdal-dev packages via apk and define the necessary paths so that the python libraries can find them.
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.