From 483dc92552f84af599f0577a8f6871255ad7b790 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 25 Jan 2018 15:29:19 +0000 Subject: [PATCH 1/8] add a Dockerfile It seems to work for me ... test with: docker build \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ -t /structural-pipeline:latest . Fetching the FSL key seems a little unreliable, I'm not sure why. If you get an error, try just running again. see https://github.com/DevelopingHCP/structural-pipeline/issues/2 --- Dockerfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d08162a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +## Build Docker image for execution of dhcp pipelines within a Docker +## container with all modules and applications available in the image +## +## How to build the image: +## - Change to top-level directory of structural-pipeline source tree +## - Run "docker build --build-arg VCS_REF=`git rev-parse --short HEAD` -t /structural-pipeline:latest ." +## +## Upload image to Docker Hub: +## - Log in with "docker login" if necessary +## - Push image using "docker push /structural-pipeline:latest" +## + +FROM ubuntu:xenial +MAINTAINER John Cupitt +LABEL Description="dHCP structural-pipeline" Vendor="BioMedIA" + +# Git repository and commit SHA from which this Docker image was built +# (see https://microbadger.com/#/labels) +ARG VCS_REF +LABEL org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/DevelopingHCP/structural-pipeline" + +# No. of threads to use for build (--build-arg THREADS=8) +# By default, all available CPUs are used. When a Docker Machine is used, +# set the number of CPUs in the VirtualBox VM Settings. +ARG THREADS + +# install prerequsites +# - FSL +# - build tools + +RUN apt-get update +RUN apt-get install -y apt-utils wget +RUN wget -O- http://neuro.debian.net/lists/artful.de-m.full | tee /etc/apt/sources.list.d/neurodebian.sources.list +RUN apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 +RUN apt-get update +RUN apt-get install -y \ + fsl-complete \ + g++-5 git cmake unzip bc python python-contextlib2 \ + libtbb-dev libboost-dev zlib1g-dev libxt-dev libexpat1-dev \ + libgstreamer1.0-dev libqt4-dev + +COPY . /usr/src/structural-pipeline +RUN ls /usr/src/structural-pipeline \ + && NUM_CPUS=${THREADS:-`cat /proc/cpuinfo | grep processor | wc -l`} \ + && echo "Maximum number of build threads = $NUM_CPUS" \ + && cd /usr/src/structural-pipeline \ + && ./setup.sh -j $NUM_CPUS + From 2149876dbd26554cf547268cc572a801cecdcb0b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 25 Jan 2018 17:00:30 +0000 Subject: [PATCH 2/8] add notes to README I made it urge people to do a build in docker, perhaps that's not wise --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 9c79beb..277fccf 100755 --- a/README.md +++ b/README.md @@ -23,6 +23,39 @@ A. Makropoulos and E. C. Robinson et al. "The Developing Human Connectome Projec ## License The dHCP structural pipeline is distributed under the terms outlined in LICENSE.txt +## Install and run with docker +You can build the pipeline in a docker container. This will work on any +version of any platform, is automated, and fairly simple. First, install +docker: + +https://docs.docker.com/engine/installation/ + +Then in the top directory of `structural-pipeline`, use git to switch to the +branch you want to build and enter: + +``` +# docker build -t /structural-pipeline:latest . +``` + +Substituting `` for your username. This command must be run as root. + +This will create a single docker image containing all the required files +and all required dependencies. + +You can then execute the pipeline like this (for example): + +``` +# docker run --rm \ + -t /structural-pipeline:latest \ + sh -c "cd /usr/src/structural-pipeline; ./dhcp-pipeline.sh \ + subject1 session1 44 \ + -T2 subject1-T2.nii.gz -T1 subject1-T1.nii.gz -t 8" +``` + +## Install locally +If you want to work on the code of the pipeline, it can be more convenient to +install locally to your machine. Only read on if you need to do a local +install. ## Dependencies #### 1. FSL From 344aac9768c07aaab4b6cb63b243e2c920e2a162 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 26 Jan 2018 10:14:39 +0000 Subject: [PATCH 3/8] README polish --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 277fccf..67ecae9 100755 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ docker: https://docs.docker.com/engine/installation/ Then in the top directory of `structural-pipeline`, use git to switch to the -branch you want to build and enter: +branch you want to build, and enter: ``` # docker build -t /structural-pipeline:latest . @@ -39,7 +39,8 @@ branch you want to build and enter: Substituting `` for your username. This command must be run as root. -This will create a single docker image containing all the required files +This will create a single docker image called +`/structural-pipeline:latest` containing all the required files and all required dependencies. You can then execute the pipeline like this (for example): @@ -47,11 +48,13 @@ You can then execute the pipeline like this (for example): ``` # docker run --rm \ -t /structural-pipeline:latest \ - sh -c "cd /usr/src/structural-pipeline; ./dhcp-pipeline.sh \ - subject1 session1 44 \ - -T2 subject1-T2.nii.gz -T1 subject1-T1.nii.gz -t 8" + sh -c "cd /usr/src/structural-pipeline; \ + ./dhcp-pipeline.sh subject1 session1 44 \ + -T2 subject1-T2.nii.gz -T1 subject1-T1.nii.gz -t 8" ``` +Again, this must be run as root. + ## Install locally If you want to work on the code of the pipeline, it can be more convenient to install locally to your machine. Only read on if you need to do a local From ebd2be4fef86437101416550f26ef498bcd40478 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 26 Jan 2018 14:12:33 +0000 Subject: [PATCH 4/8] improve notes on running the pipeline --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 67ecae9..05a8640 100755 --- a/README.md +++ b/README.md @@ -46,14 +46,16 @@ and all required dependencies. You can then execute the pipeline like this (for example): ``` -# docker run --rm \ - -t /structural-pipeline:latest \ +# docker run --rm -t -v $PWD/data:/data \ + /structural-pipeline:latest \ sh -c "cd /usr/src/structural-pipeline; \ - ./dhcp-pipeline.sh subject1 session1 44 \ - -T2 subject1-T2.nii.gz -T1 subject1-T1.nii.gz -t 8" + ./dhcp-pipeline.sh subject1 session1 44 \ + -T2 /data/sub-CC00183XX11_ses-60300_T2w.nii.gz -t 8" ``` -Again, this must be run as root. +Again, this must be run as root. This will mount the subdirectory `data` of +your current directory as `/data` in the container, then execute the pipeline +on the file `sub-CC00183XX11_ses-60300_T2w.nii.gz`. ## Install locally If you want to work on the code of the pipeline, it can be more convenient to From 5496a8423318483cf0d151a9acf7272ee73ef719 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 26 Jan 2018 15:07:07 +0000 Subject: [PATCH 5/8] update pipeline script for FSL 5 prefix fsl5 has "fsl5.0-" in front of all exe names the dockerfile needs to get root shell to run the fsl init script --- Dockerfile | 1 + dhcp-pipeline.sh | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d08162a..8e6badf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,7 @@ RUN apt-get install -y \ g++-5 git cmake unzip bc python python-contextlib2 \ libtbb-dev libboost-dev zlib1g-dev libxt-dev libexpat1-dev \ libgstreamer1.0-dev libqt4-dev +RUN echo . /etc/fsl/fsl.sh >> /root/.bashrc COPY . /usr/src/structural-pipeline RUN ls /usr/src/structural-pipeline \ diff --git a/dhcp-pipeline.sh b/dhcp-pipeline.sh index 196ab0e..50255dc 100755 --- a/dhcp-pipeline.sh +++ b/dhcp-pipeline.sh @@ -1,5 +1,9 @@ #!/bin/bash +# fsl prefix ... this was blank for fsl4, but fsl5+ have a versioned command +# prefix +fslprefix=fsl5.0- + usage() { base=$(basename "$0") @@ -130,7 +134,7 @@ for modality in T1 T2;do if [ $noreorient -eq 1 ];then cp $mf $newf else - fslreorient2std $mf $newf + ${fslprefix}fslreorient2std $mf $newf fi eval "$modality=$newf" done From 8d9588315d20c64d20a253d86a277750e87ef2fb Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 1 Feb 2018 13:42:37 +0000 Subject: [PATCH 6/8] can now run the pipeline successfully --- Dockerfile | 1 - README.md | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e6badf..d08162a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,6 @@ RUN apt-get install -y \ g++-5 git cmake unzip bc python python-contextlib2 \ libtbb-dev libboost-dev zlib1g-dev libxt-dev libexpat1-dev \ libgstreamer1.0-dev libqt4-dev -RUN echo . /etc/fsl/fsl.sh >> /root/.bashrc COPY . /usr/src/structural-pipeline RUN ls /usr/src/structural-pipeline \ diff --git a/README.md b/README.md index 05a8640..7209398 100755 --- a/README.md +++ b/README.md @@ -48,14 +48,25 @@ You can then execute the pipeline like this (for example): ``` # docker run --rm -t -v $PWD/data:/data \ /structural-pipeline:latest \ - sh -c "cd /usr/src/structural-pipeline; \ + bash -c ". /etc/fsl/fsl.sh; \ + cd /usr/src/structural-pipeline; \ ./dhcp-pipeline.sh subject1 session1 44 \ - -T2 /data/sub-CC00183XX11_ses-60300_T2w.nii.gz -t 8" + -d /data -T2 /data/sub-CC00183XX11_ses-60300_T2w.nii.gz -t 8" ``` Again, this must be run as root. This will mount the subdirectory `data` of your current directory as `/data` in the container, then execute the pipeline -on the file `sub-CC00183XX11_ses-60300_T2w.nii.gz`. +on the file `sub-CC00183XX11_ses-60300_T2w.nii.gz`. The output files will be +written to your `data` subdirectory. + +## Run interactively +Handy for debugging: + +``` +# sudo docker run \ + -v /home/john/pics/dhcp/data:/data \ + -it john/structural-pipeline:latest /bin/bash +``` ## Install locally If you want to work on the code of the pipeline, it can be more convenient to From efd3fb35e1a2cbd5d68c2e5bebccdcb837ab8b01 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 5 Feb 2018 15:50:20 +0000 Subject: [PATCH 7/8] add note about -u argument to docker --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7209398..3821e48 100755 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ You can then execute the pipeline like this (for example): ``` # docker run --rm -t -v $PWD/data:/data \ + -u $(id -u ):$(id -g ) \ /structural-pipeline:latest \ bash -c ". /etc/fsl/fsl.sh; \ cd /usr/src/structural-pipeline; \ From c020a3739749df51db86abbce1c80a2dd9dcde6e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 5 Feb 2018 16:00:17 +0000 Subject: [PATCH 8/8] tweak README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3821e48..e020e2f 100755 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ You can then execute the pipeline like this (for example): Again, this must be run as root. This will mount the subdirectory `data` of your current directory as `/data` in the container, then execute the pipeline on the file `sub-CC00183XX11_ses-60300_T2w.nii.gz`. The output files will be -written to your `data` subdirectory. +written to the `data` subdirectory. ## Run interactively Handy for debugging: