Disclaimer: these dockers use the geodecision decision making-tools Python package
In order to easily share and deploy our applications and processes, we use Docker.
Working with geospatial libraries (like geopandas) under Python could be problematic if they are not correctly installed.
That's why we use the Conda environnement to install them and create virtual environnement. For more explanations about it, see the warnings in the geodecision readme.
To illustrate the process, we have created a DockerContext example: TestGetParks_DockerContext. Python methods makes some requests on OpenStreetMap using parameters set in a config.json file.
To set our docker, we need:
- Miniconda Python 3 image on DockerHub (continuumio/miniconda3) => get it from DockerHub via the
FROM
command in the Dockerfile - a conda virtual environnement (usually it is not required as we already run our Python modules inside a Docker container but we prefer to proceed this way in order to make the development and debugging easier for the developers) that will be set via a YAML file. For details, you can check documentation here and here:
name: osm_query_env channels: - defaults - conda-forge dependencies: - geojson=2.4.1 - geopandas=0.6.0 - pip: - overpass==0.6.1
- Python modules and JSON parameters:
- A Python entrypoint to run our Docker and set the inputs and outputs (see the figure for more details):
import subprocess import json import os import shutil subprocess.call(["conda", "run", "-n", "osm_query_env", "python", "run.py", "/Input/config.json"]) json_config=os.path.join('/Input', 'config.json') with open(json_config) as f: params = json.load(f) output_file = params["output_file"] target_output_file = os.path.join('/Output', output_file) if os.path.isfile(output_file): shutil.copyfile(output_file, target_output_file)
- And of course a Dockerfile:
# Get Miniconda (Anaconda Python) from Docker Hub # (https://hub.docker.com/r/continuumio/miniconda3) FROM continuumio/miniconda3 # Create conda virtual environment # (see: # - https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file # - https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually # - https://pythonspeed.com/articles/activate-conda-dockerfile/) COPY env.yml . RUN conda env create -f env.yml # The code to run when container is started: COPY run.py . COPY entrypoint.py . COPY methods.py . ENTRYPOINT ["python", "/entrypoint.py"]
The docker build process requires access to the UD-geodecision github repository.
In order to transmit such credentials to the building process you should
first create a personnal access token (referenced as TOKEN
below).
Note that when required to specify the token scopes you apprently need to select repo
in order to allow for cloning.
Once you have a TOKEN
launch the following command:
docker build --build-arg git_token=<TOKEN> -t liris/geodecision DockerContext
You can now run the container with
docker run --mount src=`pwd`,target=/Input,type=bind --mount src=`pwd`,target=/Output,type=bind -it liris/geodecision
The outputs are placed in data/outputs
subdirectory.
In order to avoid errors, don't hesitate to validate your JSON file before running a docker, by using, for example, JSONLint validator (avoid sensitive information).
See the readme in the dockers' directories
- In order to debug the build container use
docker run --entrypoint /bin/bash -it liris/geodecision