Installing GDAL using pip or from source will sometimes not work in Docker environments. Using a conda environment is the preferred way to handle the dependency. 

A simple list of commands to create a conda environment, and then install GDAL.

gdal install
conda create --name myenv

conda activate myenv

conda install -c conda-forge gdal

This Dockerfile (coments included) will both install GDAL as a dependency in the yml file, and will also use the conda environment python with that python script.

FROM ubuntu:18.04

# set these variables related to miniconda

ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt-get update

RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*

# install latest miniconda

RUN wget \ \
    && mkdir /root/.conda \
    && bash -b \
    && rm -f

RUN conda --version

RUN conda clean -a


# below are extractor related commands

COPY extractor_info.json .

COPY aux_data ./aux_data

COPY config ./config

COPY landsattrend ./landsattrend

COPY models ./models

# conda related - copy the yml file for the environment

COPY environment_py38_v2_extractor.yml environment_py38_v2_extractor.yml

COPY extractor_info.json extractor_info.json




COPY requirements.txt requirements.txt


RUN ls

# mamba is much faster with solving the dependencies in yml files
# using conda can be incredibly slow

RUN conda install -c conda-forge mamba

# use mamba instead of conda to install environment from yml file

RUN mamba env create -f environment_py38_v2_extractor.yml

# the line below is necessary to make sure that the python used is the python associated
# with the conda environment

SHELL ["conda", "run", "-n", "landsattrend2", "/bin/bash", "-c"]

RUN python -m pip install --ignore-installed pyclowder

# make sure to include commands "conda" "run" to use the conda environment, instead of default python

CMD ["conda", "run", "--no-capture-output", "-n", "landsattrend2", "python","-u", "/"]

Here is the related part of the yml file:

name: landsattrend2
  - conda-forge
  - defaults
  - python=3.8
  - gdal=3.3.2

  • No labels