ENH: Support dockerized FreeSurfer installations
See original GitHub issueDescribe the problem
The vast majority of scientists I work with use Windows computers. However, parts of MNE’s source estimation stack rely on FreeSurfer, which is only available for Linux and macOS. This issue is preventing a number of my colleagues from switching to MNE-Python.
Describe your solution
Currently, FreeSurfer operations are carried out by concatenating a list of arguments and passing these to the respective FreeSurfer command line tool. This, obviously, will work only if FreeSurfer has been installed, so Windows is excluded per se.
To extend support to the Windows platform, I suggest to add support for containerized FreeSurfer installations, specifically for Docker images: Instead of invoking a FreeSurfer subprocess on the host machine, MNE-Python would execute the operation inside a Docker container. For example, instead of calling mri_watershed -T1 -useSRAS ... we’d call something along the lines of docker run -it -d mne/FreeSurfer mri_watershed -T1 -useSRAS ... Of course, we’d also need to map host directories to the appropriate places inside the container.
The user, then, would only need to acquire a FreeSurfer license file and install Docker; the rest could be done automatically. Incidentally, this would work on all platforms.
To allow switching between the local installation and the container, a kwarg freesurfer_backend could be added to the relevant Python function signatures: freesurfer_backend='native' (or 'local') uses the host installation, and freesurfer_backend='docker' uses the Docker container (and first pulls the image, if necessary). Might even be worthwhile to allow for different Docker images, e.g., docker_image='mne/FreeSurfer-extended:latest'
There is already a FreeSurfer image on Docker Hub which could serve as a base, and inspiration could be drawn from the FreeSurfer BIDS App.
Describe possible alternatives
The FreeSurfer BIDS App already dockerizes FreeSurfer for processing of BIDS-compliant data; however, currently it’s a “stand-alone” thingy without integration into MNE-Python.
If the idea of a dockerized FreeSurfer is generally liked, it might be worthwhile to discuss whether adding a new, thin abstraction layer between MNE-Python and FreeSurfer could be of advantage in case we’d like to add support for additional FreeSurfer backends later on. For example, on Windows 10, Windows Subsystem for Linux (WSL) seems like an almost natural choice.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:30 (30 by maintainers)

Top Related StackOverflow Question
Thanks for your help, @buildqa! I already have a working Docker image (slightly modified the one officially supplied by FreeSurfer), so no need for any packaging required at this time. Regarding the FREESURFER_HOME variable, of course I would always set it inside the Docker container; my question was just how to treat the variable set on the host computer 😃 Currently I‘m just following @larsoner‘s suggestion of ignoring the host‘s variable and simply setting it correctly inside the container. All working great so far.
Will share my results in a couple of days; still in a very early stage due to time constraints.
Sure, sorry I didn’t manage to work on this – I did start but then got caught up having to do too many other different things. Will pick this up again for sure, hopefully soon and with permission of @agramfort 😉