Skip to content

SIRF SuperBuild on Docker

Casper da Costa-Luis edited this page Apr 20, 2018 · 26 revisions

Docker

TL;DR

After installing docker CE and docker-compose,

git clone https://github.com/CCPPETMR/SIRF-SuperBuild
cd SIRF-SuperBuild/docker
docker-compose -f docker-compose.yml -f docker-compose.nix.yml up --no-start sirf  # if your host is linux
docker-compose -f docker-compose.yml up --no-start sirf  # if your host is windows

Then it's just

docker start -ai sirf

every time you want to play with SIRF.

docker start -ai sirf
(pyvenv) sirf:~$ python /opt/SIRF-SuperBuild/sources/SIRF/examples/Python/PET/osem_reconstruction.py

Intro

Docker is a low-overhead, container-based replacement for virtual machines (VMs).

This works best on a linux system due to:

  1. Possibility to get CUDA support within the container
  2. X11 windows displayed natively without needing e.g. a vnc server or desktop in the container

This is probably the easiest way to use SIRF due to really short installation instructions essentially consisting of:

docker-compose up --no-start sirf
docker start -ai sirf

Prerequisites

Glossary

A wonderfully tiny list of everything important to know for a basic working knowledge of docker.

  • Base image: the starting point for building a Docker image
    • analogous to a clean OS (in this case ubuntu:16.04)
  • Layer: a single build step
    • usually represented by a single line in a Dockerfile (e.g. apt-get install cmake)
  • Image: a sequence of layers (applied on top of a base image)
    • analogous to a clean OS with SIRF installed (in this case tagged ccppetmr/sirf)
  • Container: a sandboxed workspace derived from an image
    • analogous to a running virtual machine (in this case named sirf)
    • easily stoppable, restartable, disposable
    • can be thought of as end-user-created layers which would never be formally part of a redistributable image
    • can share files, network connections, and devices with the host computer

Images are built or pulled. Containers are created from them:

  • Build: typically refers to pulling a base image, then building all the layers necessary to form an image
    • usually once-off
  • Pull: typically refers to downloading an image from the internet (which someone else built)
    • usually only required when there is no source code available to allow for building locally
  • Create: typically refers to making a container from an image
    • often recreated for a semi-clean slate - especially if data is shared with the host computer so that no data is lost on disposal

SIRF Image Building and Container Creation

The docker image can be built from source using CCPPETMR/SIRF-SuperBuild by following the steps below. Alternatively, simply run docker pull ccppetmr/sirf to download a pre-built image.

docker-compose is used to help with creating containers (and even building images). It should be added to your PATH or at least have the executable copied to SIRF-SuperBuild/docker.

Linux

# Either:
SIRF-SuperBuild/docker$ docker pull ccppetmr/sirf
# Or:
SIRF-SuperBuild/docker$ docker-compose build core sirf

After this a container called sirf is created: For easier file and window sharing, the sirf container should be started using the host user's ID and some environment variables:

SIRF-SuperBuild/docker$ docker-compose -f docker-compose.yml \
  -f docker-compose.nix.yml up --no-start sirf

Windows

Either:
SIRF-SuperBuild/docker> docker pull ccppetmr/sirf
Or:
SIRF-SuperBuild/docker> docker-compose build core sirf

Instead of passing user IDs, Windows requires that file sharing is enabled. Then:

SIRF-SuperBuild/docker> docker-compose up --no-start sirf

You may want to consult SIRF-SuperBuild-on-Bash-on-Ubuntu-on-Windows-10 regarding setting up Xserver/VNCserver and other UNIX-for-Windows-users tips.

Developers

ccache is used in the container to speed up rebuilding images from scratch. The cache is pulled from the host machine via the devel/.ccache folder. To replace the host's cache with the updated one from the container, run:

SIRF-SuperBuild/docker$ sudo rm -rf devel/.ccache/*
SIRF-SuperBuild/docker$ docker-compose run --rm sirf \
  /bin/bash -c 'sudo cp -a /opt/ccache/* /devel/.ccache/'

Usage

Well, that was easy. The container can be run interactively for daily use.

SIRF-SuperBuild/docker$ docker start -ai sirf
(py2) sirf:~$ gadgetron >> /dev/null &
(py2) sirf:~$ python SIRF-SuperBuild/SIRF/examples/Python/MR/fully_sampled_recon.py

The first line starts the sirf docker container. The second line starts gadgetron within the container as a background process. Finally, we can then run an example.

Note that the devel folder in the host's SIRF-SuperBuild/docker directory is mounted to /devel in the container.

Notes

  • Tests can be run as follows:
(py2) sirf:~$ /devel/test.sh
  • "Cannot connect to display" errors are usually fixed by running xhost +local:"" on the host linux system
  • Non-linux users (e.g. Windows) will need to set up a desktop and vnc server in order to have a GUI (docker files coming soon)
  • On host systems with less than 16GB RAM, before docker-compose up ... you may want to edit SIRF-SuperBuild/docker/user_sirf-ubuntu.sh, changing the line make -j... to simply make. This increases build time and reduces build memory requirements.