# How do you run a JupterLab Docker container in privileged mode?

**URL:** <https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352>\
**Category:** General\
**Created:** [July 24, 2020, 9:38am UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352 "2020-07-24T09:38:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russell\_Seymour](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/russell_seymour/32/2428_2.png) [@Russell\_Seymour](https://discourse.jupyter.org/u/Russell_Seymour)\
**Post date:** [July 24, 2020, 9:38am UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352/1 "2020-07-24T09:38:02Z")

</div>

I have setup JupyterHub with DockerSpawner and Auth0, this is working well with stock JupyterLab images.

Now I am trying to use my own custom JupyterLab image which is based off of `base-notebaook`. However as I want to be able to access the hardware on the host machine I have enabled UDEV in the image. This means that I need to run the JupterLab container in privileged mode.

I have tried to use variations of the following to get this to work:

```auto
# Attempt to use extra_create_kwargs
c.DockerSpawner.extra_create_kwargs = {
   "privilege": True
}

# Attempt use extra_host_config
c.DockerSpawner.extra_host_config = {
   "privilege": True
}

```

I am pretty sure that I have got the name of the configuration item wrong and where it is set but I cannot work it out and I have not been able to find it in the documentation anywhere online.

So how can this be achieved?

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [July 24, 2020, 5:51pm UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352/2 "2020-07-24T17:51:43Z")

</div>

Can you try `privileged` (`d` on the end) in `extra_host_config`?:  
[https://docker-py.readthedocs.io/en/4.2.2/api.html?highlight=privileged](https://docker-py.readthedocs.io/en/4.2.2/api.html?highlight=privileged)

---

<div class="post-metadata">

**Author:** ![Russell\_Seymour](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/russell_seymour/32/2428_2.png) [@Russell\_Seymour](https://discourse.jupyter.org/u/Russell_Seymour)\
**Post date:** [July 24, 2020, 6:48pm UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352/3 "2020-07-24T18:48:55Z")

</div>

@manics Thanks again you have sorted it

I thought I had tried it with `privileged` but obviously not.

---

<div class="post-metadata">

**Author:** ![chambon](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@chambon](https://discourse.jupyter.org/u/chambon)\
**Post date:** [October 6, 2021, 4:38pm UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352/6 "2021-10-06T16:38:40Z")

</div>

Hello,  
I tried several cases for `"privileged": True` with DockerSpawner (version 12) but without any success.  
I always got error rmessage “`unexpected keyword argument `” whatever I tried to set it  
via `.extra_container_spec` or `.extra_host_config` or `.extra_create_kwargs`

Do I miss something ?

I also have the same problem with another keyword, I talk about `"cap-add": "SYS_PTRACE"` (to be allowed to run `strace` inside a container)  
But this is ok if I run the container via `docker run`, I mean `docker run --cap-add=SYS_PTRACE ...`  
Any feedback on this would also be appreciated

Regards,  
Bernard

---

<div class="post-metadata">

**Author:** ![chambon](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@chambon](https://discourse.jupyter.org/u/chambon)\
**Post date:** [March 26, 2025, 8:24am UTC](https://discourse.jupyter.org/t/how-do-you-run-a-jupterlab-docker-container-in-privileged-mode/5352/8 "2025-03-26T08:24:45Z")

</div>

Hello, Is it possible to have privileged mode when using the `swarmspawner` ? (not dockerspawner)  
This question because with `swarmspawner`, JupyterLab container are launched as docker services and as far I know `docker service create` doesn’t allow nor privileged nor security\_opt options.

So I would tend to think that by using`swarmspawner` in a cluster/swarm wont’ allow to have the required permissions for running apptainer commands in a Jupterlab terminal (my objective) Am I right?

To move forward, I tried with cap-add option `docker service ... --cap-add=SYS_ADMIN ` option (options possible with docker service create) , but on worker node side, when testing via `docker exec -it abcdefgh apptainer run docker://alpine echo "Hello world"` I get error like ‘failed to attach loop device’

My last attempt was to start dockerd, on a worker node, with user namespaces allowed, but consequently the worker disappears from the swarm cluster.

Any tips for another solution ? Or is it definitely impossible to run `apptainer` commands from jupyterLab’s terminal, launch in a **docker/swarm** cluster ?

Regards
