Using Docker
This short guide should be viewed as a companion to the DAFNI Model preparation guide. You can also find several useful guides, and the docker manual, on the docker webpage.
Docker : A Quick Guide
When you are uploading a model to DAFNI, it will be a computer model that is written in one of a myriad of different computer languages, and will often use multiple external libraries. One of the challenges in using such a model, is ensuring the model is consistent when running it on different machines (and sometimes with different operating systems). An aspect that people sometimes overlook is that when you are compiling and running computer code on your machine, though it may superficially look just like another computer down the corridor, the two computers may in fact be set up very differently. Taking the example of Python, Python will often have different libraries installed on top of the base-level Python you download - the versions can vary from machine to machine, they could even be on your computer but missing on others, the Python itself can be a different version. The same goes for other languages too, libraries that may be used when compiling your code may be missing on other machines, resulting in your model code not compiling or running on other computers. What docker essentially does is create a miniature facimile of your local computer setup so this problem can be avoided.
Downloading & Installing Docker
The very first thing you will need to is to download and install Docker. You should note that there are actually two different flavours of Docker, for most users we recommend that you obtain Docker Desktop, but more advanced users may chose to use Docker Engine. For the purposes of containerising a model for DAFNI, the more limited Desktop version will be fine.
Note, one thing that many not be particularly obvious is the backend setup on Windows - you will need to do this for Windows installations. There are two tabs under system requirements and you have to pick either WSL2 or Windows Containers. Either of these should work, I use WSL2 myself (Windows System for Linux) but this is a personal preference. A guide to switching on WSL2 can be found in the Microsoft WSL Guide. Directions are provided on the docker page for the alternative backend.
Tips for Using Docker
One thing to keep in mind is that you'll need to manually start Docker Desktop (or Docker Engine - if you have it installed and it isn't set to run automatically) and have it running in the background, before running 'docker' commands !
Tip: On Windows, you may find the output text colours are quite hard to read when running docker from the command line (powershell especially). You can use the flag --progress=plain if you encounter this issue.
docker build --progress=plain -t test-example .
Tip: Occasionally you may wish to start a docker container in an interactive terminal, you can do this using the following command (the specific example command below demonstates how to start an interactive python session in a terminal using docker)
docker run -it python:3.9
If you would like to mount a directory to use in a docker container you can do this using the following command. This will run interactive docker session, allowing access to the data stored in $HOME/pythia (it wouldn't be visible within the docker session otherwise, this way it can be found in /home/pythia inside the session)
docker run -it -v $HOME/pythia:/home/pythia python:3.9