Installing extension inside a Dockerfile

I am trying to build a Dockerfile where I can install the extensions. I am following the instructions in here

As I understand, that requires knowing what folders exist in the lib/Slicer-4.11/ for every extension beforehand and adding those paths one by one to Slicer --additional-module-paths to enable them.

We have a number of extensions to install. Is there a more compact way doing this?

It’s possible to set up a custom .ini file with all the paths listed. Or you can copy all the files into a common lib directory and specify that on the command line.

Another option is to let the extension manager install the extension, as it is done in SlicerJupyter docker image:

Yet another option would be to run slicer as part of the docker build step and have it programmatically access the needed extensions. This has the advantage that you don’t need to hard code the package URLs, only the extension names.


I have tried this approach. BUT, slicer ask for restart and if you just call another slicer command it says the extension is not properly installed. See these errors.

Hmm, I haven’t tried but that sounds fixable.

I don’t see any errors related to extension install.

Once the extension is installed, you don’t need to restart Slicer, just exit Slicer and when you start it next time it works well. You can see how it works in SlicerJupyter docker image (see link above).

I think this will work for me the simplest. Thanks.

assuming the extensions to be installed in

docker command
RUN /opt/slicer/bin/Slicer --no-main-window --python-script ./
fails due to lack of X environment. specific error:

qt.qpa.screen: QXcbConnection: could not connect to display Could not connect to any X display

You can use the SlicerJupyter docker image as an example of setting up display properly and use Slicer’s extension manager to install the extension. By following @pieper’s suggestion you can make installation even simpler (by making extension manager download the extension, too, instead of manually downloading it from a URL).

dear Andras, my question is how to Slicer’s extension manager to install the extension. Cause docker container is non-GUI. Please help me. Thanks a lot .
Btw, my question is report here.

Showing GUI or not is your choice, but you need to set up a display server to run the full application. It does not mean that you need to display a GUI at the host.

The slicer-notebook docker image that I linked above installs SlicerJupyter. Replace that by SlicerElastix and you are good.

Another option for this is to use xvfb-run in your Dockerfile like this example.

FYI, I don’t think the download/wget links in that image is valid anymore. I think they refer to old midas server that doesn’t exist, I think…

I mean I don’t want to use slicer-Jupyter-notebook, I just want to use slicer with SlicerRT extension in the docker container, and execute python script like this

/xxx/Slicer-X-Y-linux-amd64/Slicer --no-main-window --python-script ./

You can jusr just the relevant parts of the image: setting up the display server and installing an extension. There are many other Slicer docker images for various purposes. You can find references to them in posts in this forum.

Unfortunately, we don’t have a single location where all the images are listed at, but we could create it now. @pieper, @muratmaga, @mau_igna_06 what do you think about adding links to all known Slicer docker (and singularity, etc.) images at SlicerDocker/README.rst at master · Slicer/SlicerDocker · GitHub? The earlier idea of having a single hierarchy of images may be unrealistic, but at least collecting links (with a 1-2 sentence description of each) at a single location should be feasible.

1 Like

This makes sense. And since it’s still an active topic we could add links to the discourse threads as well.

Yes. No problem Andras