# Installing extension inside a Dockerfile

**URL:** https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925
**Category:** Support
**Created:** [October 7, 2020, 5:17pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925 "2020-10-07T17:17:40Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [October 7, 2020, 5:17pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/1 "2020-10-07T17:17:40Z")

</div>

I am trying to build a Dockerfile where I can install the extensions. I am following the instructions in [here](https://www.slicer.org/wiki/Documentation/Nightly/SlicerApplication/ExtensionsManager#How_to_manually_install_an_extension_package.3F)

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?

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [October 7, 2020, 6:11pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/2 "2020-10-07T18:11:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 7, 2020, 6:16pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/3 "2020-10-07T18:16:30Z")

</div>

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

> <https://github.com/Slicer/SlicerDocker/blob/c13632a1061371937f73acf9d42c605850f7b3bb/slicer-notebook/Dockerfile#L130-L140>

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [October 7, 2020, 6:21pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/4 "2020-10-07T18:21:04Z")

</div>

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.  
[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Download\_and\_install\_extension](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Download_and_install_extension)

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)
#### Post date: [October 7, 2020, 6:26pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/5 "2020-10-07T18:26:04Z")

</div>

> [@pieper](#):
>
> Yet another option would be to run slicer as part of the docker build step and have it programmatically access the needed extensions.

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](https://gitlab.com/opendose/opendose3d/-/issues/26).

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [October 7, 2020, 6:28pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/6 "2020-10-07T18:28:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 7, 2020, 6:41pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/7 "2020-10-07T18:41:44Z")

</div>

> [@Alex\_Vergara](#):
>
> 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](https://gitlab.com/opendose/opendose3d/-/issues/26).

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).

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [October 7, 2020, 8:53pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/8 "2020-10-07T20:53:45Z")

</div>

> [@pieper](#):
>
> 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

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

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [October 8, 2020, 4:25am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/9 "2020-10-08T04:25:01Z")

</div>

assuming the extensions to be installed in extensions.py

docker command  
`RUN /opt/slicer/bin/Slicer --no-main-window --python-script ./extensions.py`  
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`

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [October 8, 2020, 4:52am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/10 "2020-10-08T04:52:09Z")

</div>

You can use the [SlicerJupyter docker image](https://github.com/Slicer/SlicerDocker/blob/c13632a1061371937f73acf9d42c605850f7b3bb/slicer-notebook/Dockerfile) 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).

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 30, 2021, 9:36am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/11 "2021-12-30T09:36:14Z")

</div>

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. [https://discourse.slicer.org/t/how-to-install-slicerrt-extension-in-docker-slicerdocker-container/21270?u=rosenty](https://discourse.slicer.org/t/how-to-install-slicerrt-extension-in-docker-slicerdocker-container/21270)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 30, 2021, 5:58pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/12 "2021-12-30T17:58:08Z")

</div>

> [@ROSENty](#):
>
> Cause docker container is non-GUI

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.

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [December 30, 2021, 7:52pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/13 "2021-12-30T19:52:17Z")

</div>

> [@muratmaga](#):
>
> assuming the extensions to be installed in extensions.py
> 
> docker command  
> `RUN /opt/slicer/bin/Slicer --no-main-window --python-script ./extensions.py`  
> 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`

Another option for this is to use `xvfb-run` in your `Dockerfile` like [this example](https://github.com/pieper/SlicerDockers/blob/master/slicer-plus/Dockerfile#L8-L21).

---

<div class="post-metadata">

### Author: ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)
#### Post date: [December 31, 2021, 12:08am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/14 "2021-12-31T00:08:33Z")

</div>

> [@lassoan](#):
>
> You can use the [SlicerJupyter docker image](https://github.com/Slicer/SlicerDocker/blob/c13632a1061371937f73acf9d42c605850f7b3bb/slicer-notebook/Dockerfile) as a

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…

---

<div class="post-metadata">

### Author: ![ROSENty](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rosenty/32/13334_2.png) [@ROSENty](https://discourse.slicer.org/u/ROSENty)
#### Post date: [December 31, 2021, 7:48am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/15 "2021-12-31T07:48:34Z")

</div>

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 [https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/9?u=rosenty](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/9)

```auto
/xxx/Slicer-X-Y-linux-amd64/Slicer --no-main-window --python-script ./myTest.py

```

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 31, 2021, 3:11pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/16 "2021-12-31T15:11:02Z")

</div>

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](https://github.com/Slicer/SlicerDocker/blob/master/README.rst)? 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.

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [December 31, 2021, 7:02pm UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/17 "2021-12-31T19:02:09Z")

</div>

> [@lassoan](#):
>
> 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](https://github.com/Slicer/SlicerDocker/blob/master/README.rst)?

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

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [January 1, 2022, 12:56am UTC](https://discourse.slicer.org/t/installing-extension-inside-a-dockerfile/13925/18 "2022-01-01T00:56:22Z")

</div>

> [@lassoan](#):
>
> 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](https://github.com/Slicer/SlicerDocker/blob/master/README.rst)?

Yes. No problem Andras
