|
| 1 | +.. include:: links.rst |
| 2 | + |
| 3 | +.. _run_docker: |
| 4 | + |
| 5 | +Running *fMRIPrep* via Docker containers |
| 6 | +======================================== |
| 7 | +For every new version of *fMRIPrep* that is released, a corresponding Docker |
| 8 | +image is generated. |
| 9 | +The Docker image *becomes* a container when the execution engine loads the |
| 10 | +image and adds an extra layer that makes it *runnable*. |
| 11 | +In order to run *fMRIPrep* Docker images, the Docker Engine must be installed |
| 12 | +(see :ref:`installation_docker`). |
| 13 | + |
| 14 | +If you used *fMRIPrep* via Docker in the past, you might need to pull down a |
| 15 | +more recent version of the image: :: |
| 16 | + |
| 17 | + $ docker pull poldracklab/fmriprep:<latest-version> |
| 18 | + |
| 19 | +You can run *fMRIPrep* interacting directly with the Docker Engine via the `docker run` |
| 20 | +command line, or you can use a lightweight wrapper we created for convenience. |
| 21 | + |
| 22 | +.. _docker_wrapper: |
| 23 | + |
| 24 | +Running *fMRIPrep* with the ``fmriprep-docker`` wrapper |
| 25 | +------------------------------------------------------- |
| 26 | +Before starting, make sure you |
| 27 | +`have the wrapper installed <installation.html#the-fmriprep-docker-wrapper>`__. |
| 28 | +When you run ``fmriprep-docker``, it will generate a Docker command line for you, |
| 29 | +print it out for reporting purposes, and then execute it without further action |
| 30 | +needed, e.g.:: |
| 31 | + |
| 32 | + $ fmriprep-docker /path/to/data/dir /path/to/output/dir participant |
| 33 | + RUNNING: docker run --rm -it -v /path/to/data/dir:/data:ro \ |
| 34 | + -v /path/to_output/dir:/out poldracklab/fmriprep:1.0.0 \ |
| 35 | + /data /out participant |
| 36 | + ... |
| 37 | + |
| 38 | +``fmriprep-docker`` accepts all of the typical options for *fMRIPrep* (see :ref:`usage`), |
| 39 | +automatically translating directories into Docker mount points. |
| 40 | + |
| 41 | +We have published a `step-by-step tutorial |
| 42 | +<http://reproducibility.stanford.edu/fmriprep-tutorial-running-the-docker-image/>`_ |
| 43 | +illustrating how to run ``fmriprep-docker``. |
| 44 | +This tutorial also provides valuable troubleshooting insights and advice on |
| 45 | +what to do after *fMRIPrep* has run. |
| 46 | + |
| 47 | + |
| 48 | +Running *fMRIPrep* directly interacting with the Docker Engine |
| 49 | +-------------------------------------------------------------- |
| 50 | +If you need a finer control over the container execution, or you feel comfortable |
| 51 | +with the Docker Engine, avoiding the extra software layer of the wrapper might be |
| 52 | +a good decision. |
| 53 | + |
| 54 | +**Accessing filesystems in the host within the container**. |
| 55 | +Containers are confined in a sandbox, so they can't access the host in any ways unless |
| 56 | +you explicitly prescribe acceptable accesses to the host. |
| 57 | +The Docker Engine provides mounting filesystems into the container with the ``-v`` argument |
| 58 | +and the following syntax: ``-v some/path/in/host:/absolute/path/within/container:ro``, |
| 59 | +where the trailing ``:ro`` specifies that the mount is read-only. |
| 60 | +The mount permissions modifiers can be omitted, which means the mount will have read-write |
| 61 | +permissions. |
| 62 | +In general, you'll want to at least provide two mount-points: one set in read-only mode |
| 63 | +for the input data and one read/write to store the outputs. |
| 64 | +Potentially, you'll want to provide one or two more mount-points: one for the working |
| 65 | +directory, in case you need to debug some issue or reuse pre-cached results; and |
| 66 | +a :ref:`TemplateFlow` folder to preempt the download of your favorite templates in every |
| 67 | +run. |
| 68 | + |
| 69 | +**Running containers as a user**. |
| 70 | +By default, Docker will run the container as **root**. |
| 71 | +Some share systems my limit this feature and only allow running containers as a user. |
| 72 | +When the container is run as **root**, files written out to filesystems mounted from the |
| 73 | +host will have the user id ``1000`` by default. |
| 74 | +In other words, you'll need to be able to run as root in the host to change permissions |
| 75 | +or manage these files. |
| 76 | +Alternatively, running as a user allows preempting these permissions issues. |
| 77 | +It is possible to run as a user with the ``-u`` argument. |
| 78 | +In general, we will want to use the same user ID as the running user in the host to |
| 79 | +ensure the ownership of files written during the container execution. |
| 80 | +Therefore, you will generally run the container with ``-u $( id -u )``. |
| 81 | + |
| 82 | +You may also invoke ``docker`` directly:: |
| 83 | + |
| 84 | + $ docker run -ti --rm \ |
| 85 | + -v path/to/data:/data:ro \ |
| 86 | + -v path/to/output:/out \ |
| 87 | + poldracklab/fmriprep:<latest-version> \ |
| 88 | + /data /out/out \ |
| 89 | + participant |
| 90 | + |
| 91 | +For example: :: |
| 92 | + |
| 93 | + $ docker run -ti --rm \ |
| 94 | + -v $HOME/ds005:/data:ro \ |
| 95 | + -v $HOME/ds005/derivatives:/out \ |
| 96 | + -v $HOME/tmp/ds005-workdir:/work \ |
| 97 | + poldracklab/fmriprep:<latest-version> \ |
| 98 | + /data /out/fmriprep-<latest-version> \ |
| 99 | + participant \ |
| 100 | + -w /work |
| 101 | + |
| 102 | +Once the Docker Engine arguments are written, the remainder of the command line follows |
| 103 | +the :ref:`usage`. |
| 104 | +In other words, the first section of the command line is all equivalent to the ``fmriprep`` |
| 105 | +executable in a bare-metal installation: :: |
| 106 | + |
| 107 | + $ docker run -ti --rm \ | These lines |
| 108 | + -v $HOME/ds005:/data:ro \ | are equivalent |
| 109 | + -v $HOME/ds005/derivatives:/out \ | to the fmriprep |
| 110 | + -v $HOME/tmp/ds005-workdir:/work \ | executable. |
| 111 | + poldracklab/fmriprep:<latest-version> \ | |
| 112 | + \ |
| 113 | + /data /out/fmriprep-<latest-version> \ | These lines |
| 114 | + participant \ | correspond to |
| 115 | + -w /work | fmriprep arguments. |
0 commit comments