How To Create Your First Docker For Geospatial Environment
Tags: GIS, Geospatial, Docker, Python, Data Science

Docker is transforming modern applications. You might have heard about it and wondered how it is beneficial to your geospatial data science applications? Or, more probably, how do you get started?

In this post, I will go through what Docker containers are and their benefits. I will also cover the complete running of an entire geospatial Jupyter environment with Docker step by step. Finally, I will point you to the resources to customize and advance to the next level.

What is Docker

Docker is a tool for running applications in an isolated environment (similar VM). The underlying concept of docker has been around before docker, but Docker revolutionized it and made a cohesive and easy to use technology. They achieve this through containerization.

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines — Source

There are many other containers, but most of the time, people use docker. We now use docker to be synonymous with containers.

Containers differ from virtual machines. While Virtual machines are an abstraction on top of physical hardware, converting one server into multiple servers, containers are an abstraction on top of the app layer and its dependencies.

Containers vs. Virtual Machines

There are several benefits to containerization, including the following:

Multiple containers can run on the same machine, and each container in an isolated process.

Containers take less space than VM.

You can run containers in minutes, with less memory since it does not need the full OS.

We can deploy and test containers everywhere.

Docker Terminology

I have grappled for some time with the difference between docker images and containers. You can think of docker images as templates and containers as an actual instance of the template.

Docker Hub has an extensive repository of images. You can either create and push your image to Docker Hub or pull a ready-made image. Even when you are making an image, you can have a base image instead of building it from scratch.

On the other hand, a Docker container is a running instance of the Docker image. Here, we interact with Docker and can create multiple instances of an image.

Before I go through Creating a docker environment for geospatial data science, Here are some useful terminologies:

docker pull — to pull images from Docker Hub.

docker push — to push images you build with Dockerfile.

docker run — Create a container from an image.

docker ps — List out running containers.

docker ps -a — List out all running and stopped containers.

docker stop — Stop a running container.

docker rm — Remove a stopped container.

docker images — List out all images.

docker build — Build images from Dockerfile.

Create a working Jupyter Environment with Docker

Before we can start pulling and creating a working environment in Docker, we need to install Docker. Installing docker has become easy even in Windows 10 now. Go to Docker Documentation and install docker. For Windows or Mac users, you need to download Docker Desktop. I use WIndows so, I have installed Docker Desktop for Windows.

You also need to create a Docker Hub account and sign in to the Desktop application or from the terminal.

Now let us start creating a Docker environment for Geospatial Data Science. In Docker Hub, you can search for available images.

Here are some of the popular Geospatial Data science Images available:

The Docker-based Geospatial toolkit for R — built on versioned by Rocker images.

Ubuntu with python packages for working the geospatial netCDF data and some helper packages. — geospatial-python.

All-encompassing Geospatial Data Science Container (Python + R) — GDS.

Let me go through the steps to pull a Geospatial data science Jupyter Environment image and create a running container. In this demo, I will use the gds_py image created by Darribas. It has all the packages you need for geospatial data science in Python.

Go to a terminal First and pull the image with the following command:

docker pull darribas/gds_py

When we execute the command above, it starts to download the image and might take a while, depending on the image size. Once it is complete, you can check Docker's image for Desktop or just run the following command in your terminal.

docker images

Now that we have a Docker image, we can create instances from it. We can use the run command and provide the port and also mount a local folder.

docker run -p 9999:8888 -v C:\Users\shaka\Desktop\D:/home/jovyan/work darribas/gds_py

-p: we are forwarding port 8888 to 9999. So when we want to access Jupyter Lab, we need to specify this port. We will see that later.

-v: We are mounting a local file for persistence. Even when we stop the container and start again, we will have our Jupyter notebooks.

After we execute the above command, we will get a link running Jupyter Lab. Copy that link and paste it into your browser. Before running, change the port if you had a different forwarding port. In our case, we had 9999. So change only the port to 9999 and hit enter.