skip to Main Content

I want to build a Docker container with a Python Dash App. The app requires geospatial packages like Geopandas, Folium, Shapely. When trying to build the Docker Image it fails when trying to install Fiona, it says it requires GDAL. I don’t know exacly how to install the gdal package to the base image.

Dockerfile

FROM python:3.8-slim
WORKDIR /code 
COPY ./requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt && rm -rf /root/.cache
COPY ./ /code/
CMD ["gunicorn","-b","0.0.0.0:8080","index:server"]

requirements.txt

attrs==21.2.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
branca==0.4.2; python_version >= "3.5"
brotli==1.0.9; python_version >= "3.6"
certifi==2021.10.8; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.8"
charset-normalizer==2.0.10; python_full_version >= "3.6.0" and python_version >= "3.5"
chart-studio==1.1.0
click-plugins==1.1.1; python_version >= "3.7"
click==8.0.3; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version < "4" and python_version >= "3.7"
cligj==0.7.2; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version < "4" and python_version >= "3.7"
colorama==0.4.4; python_version >= "3.7" and python_full_version < "3.0.0" and platform_system == "Windows" or platform_system == "Windows" and python_version >= "3.7" and python_full_version >= "3.5.0"
cycler==0.11.0; python_version >= "3.7"
dash-auth==1.4.1
dash-bootstrap-components==1.0.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0" and python_version < "4")
dash-core-components==2.0.0; python_version >= "3.6"
dash-daq==0.5.0
dash-html-components==2.0.0; python_version >= "3.6"
dash-table==5.0.0; python_version >= "3.6"
dash==2.0.0; python_version >= "3.6"
fiona==1.8.20; python_version >= "3.7"
flask-compress==1.10.1; python_version >= "3.6"
flask-seasurf==0.3.1
flask==2.0.2; python_version >= "3.6"
folium==0.12.1.post1; python_version >= "3.5"
fonttools==4.29.1; python_version >= "3.7"
geopandas==0.10.2; python_version >= "3.7"
gunicorn==20.1.0; python_version >= "3.5"
idna==3.3; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.5"
itsdangerous==2.0.1; python_version >= "3.6"
jinja2==3.0.3; python_version >= "3.6"
joblib==1.1.0; python_version >= "3.7"
kiwisolver==1.3.2; python_version >= "3.7"
mapclassify==2.4.3
markupsafe==2.0.1; python_version >= "3.6"
matplotlib==3.5.1; python_version >= "3.7"
munch==2.5.0; python_version >= "3.7"
networkx==2.6.3; python_version >= "3.7"
numpy==1.21.1; python_version >= "3.7"
packaging==21.3; python_version >= "3.7"
pandas==1.3.4; python_full_version >= "3.7.1"
pillow==9.0.1; python_version >= "3.7"
plotly==5.4.0; python_version >= "3.6"
pyparsing==3.0.7; python_version >= "3.7"
pyproj==3.3.0; python_version >= "3.8"
python-dateutil==2.8.2; python_full_version >= "3.7.1" and python_version >= "3.7"
python-decouple==3.5
pytz==2021.3; python_full_version >= "3.7.1" and python_version >= "3.7"
requests==2.27.1; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.5"
retrying==1.3.3
rtree==0.9.7
scikit-learn==1.0.2; python_version >= "3.7"
scipy==1.6.1; python_version >= "3.7"
setuptools-scm==6.4.2; python_version >= "3.7"
shapely==1.8.0; python_version >= "3.7"
six==1.16.0; python_full_version >= "3.7.1" and python_version >= "3.7" and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.6") and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0") and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.7")
tenacity==8.0.1; python_version >= "3.6"
threadpoolctl==3.1.0; python_version >= "3.7"
tomli==2.0.0; python_version >= "3.7"
ua-parser==0.10.0
urllib3==1.26.8; python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version < "4" and python_version >= "3.5"
werkzeug==2.0.2; python_version >= "3.6"

Result when trying to build

...
#8 2.723   Downloading dash_table-5.0.0.tar.gz (3.4 kB)
#8 2.843 Collecting dash==2.0.0
#8 2.859   Downloading dash-2.0.0-py3-none-any.whl (7.3 MB)
#8 3.850 Collecting fiona==1.8.20
#8 3.882   Downloading Fiona-1.8.20.tar.gz (1.3 MB)
#8 4.187     ERROR: Command errored out with exit status 1:
#8 4.187      command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bsxe9wyf/fiona_029030bfc6284bc292763bed2693d299/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bsxe9wyf/fiona_029030bfc6284bc292763bed2693d299/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-oim_g79k
#8 4.187          cwd: /tmp/pip-install-bsxe9wyf/fiona_029030bfc6284bc292763bed2693d299/
#8 4.187     Complete output (2 lines):
#8 4.187     Failed to get options via gdal-config: [Errno 2] No such file or directory: 'gdal-config'
#8 4.187     A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
#8 4.187     ----------------------------------------
#8 4.187 WARNING: Discarding https://files.pythonhosted.org/packages/ec/f7/093890341a7e8fbfcdfa04caf4dfb588ebab32c13ceaa6a3819da79ea106/Fiona-1.8.20.tar.gz#sha256=a70502d2857b82f749c09cb0dea3726787747933a2a1599b5ab787d74e3c143b (from https://pypi.org/simple/fiona/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#8 4.188 ERROR: Could not find a version that satisfies the requirement fiona==1.8.20 (from versions: 0.5, 0.6, 0.6.1, 0.6.2, 0.7, 0.8, 0.9, 0.9.1, 0.10, 0.12, 0.12.1, 0.13, 0.14, 0.15, 0.16, 0.16.1, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.2.0, 1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.3.post1, 1.6.4, 1.7b1, 1.7.0, 1.7.0.post2, 1.7.1, 1.7.1.post1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.9.post1, 1.7.10, 1.7.10.post1, 1.7.11, 1.7.11.post1, 1.7.11.post2, 1.7.12, 1.7.13, 1.8a1, 1.8a2, 1.8a3, 1.8b1, 1.8b2, 1.8rc1, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.9.post1, 1.8.9.post2, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.13.post1, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.8.20, 1.8.21)
#8 4.188 ERROR: No matching distribution found for fiona==1.8.20
#8 4.252 WARNING: You are using pip version 21.2.4; however, version 22.0.3 is available.
#8 4.252 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip install -r requirements.txt && rm -rf /root/.cache]: exit code: 1

I appreciate any help to build this image successfully.

2

Answers


  1. My guess is that adding this before requirements installation may help

    RUN apt-get install gdal-bin
    

    I am not sure if that’s the right command to install GDAL. If it isn’t, just look up how to install it and add it to your dockerfile.

    Login or Signup to reply.
  2. I managed to solve it by adding to the Dockerfile (before the pip install -r requirements.txt) these command to install the following packages:

    RUN apt-get update
    RUN apt-get install -y gdal-bin libgdal-dev g++
    

    This increased the image size notably, but solved the issue.

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