Running QuantLib python notebooks on Docker
The typical way to get QuantLib python running in your computer is by compiling QuantLib and the SWIG bindings in your computer. I have heard from some of my blog readers that they run into issues with getting QuantLib-Python running in their system. Here I will show how you can easily get started on QuantLib-Python using Docker.
Docker is a platform for containerization of software. In other words, Docker lets one to wrap an application in a complete ecosystem needed to run the application (aka image), such as system libraries and filesystem. This means that irrespective of what operating system your computer runs, a Docker image will run reliably on the Docker containers. Docker containers are very lightweight, and it starts up in a matter of couple of seconds.
Every now and then, I would run into conflicts between the development version of QuantLib and the release version. So in order to not have such conflicts, Docker containers are a perfect solution. Every image is isolated and it is easy to load a specific version and not have any conflicts. In order to keep my Docker images minimal, I use Alpine Linux as a base instead of Ubuntu.
In order to get started on using Docker, you need to first install Docker. The first step is to get Docker itself. You can get the Docker client by going to getting started page.
Once you have done the installation, you can get quantlib-python by doing the following on a shell:
docker pull gbalaraman/quantlib-notebook
This is going to pull the quantlib-notebook image from Docker Hub. This process takes a few seconds. Think of this as the same as downloading an installer for a software.
Once you have the image downloaded, you can run quantlib-python notebooks by doing the following:
docker run -d -p 8888:8888 --mount src=<your notebook folder>,target=/home/notebooks,type=bind --name ql_notebook gbalaraman/quantlib-notebook
If you are using latest docker images published by Luigi, you should mount to
folder on the container. So in all it would look like:
docker run -d -p 8888:8888 --mount src=<your notebook folder>,target=/notebooks,type=bind --name ql_notebook2 lballabio/quantlib-notebook
Those using older docker versions, you had to do this:
docker run -d -p 8888:8888 -v <your notebook folder>:/home/notebooks/ --name ql_notebook gbalaraman/quantlib-notebook
The above command runs the image "gbalaraman/quantlib-notebook" as a daemon (-d) and
will forward the port 8888 in the container to the port 8888 in localhost (-p 8888:8888).
We are calling the container where this image runs as ql_notebook (--name ql_notebook).
When you are done you can stop the Docker container by using the command:
docker stop ql_notebook
This is equivalent to shutting down the notebook. If you want to start docker again, this time around you can start it by saying:
docker start ql_notebook