# DockerSpawner - container deletion by user choice

**URL:** <https://discourse.jupyter.org/t/dockerspawner-container-deletion-by-user-choice/8024>\
**Category:** JupyterHub\
**Created:** [February 19, 2021, 11:58am UTC](https://discourse.jupyter.org/t/dockerspawner-container-deletion-by-user-choice/8024 "2021-02-19T11:58:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [February 23, 2021, 11:23am UTC](https://discourse.jupyter.org/t/dockerspawner-container-deletion-by-user-choice/8024/4 "2021-02-23T11:23:01Z")

</div>

> I suspect that as a ordinary user you cannot in any way delete your container and start a new one

DockerSpawner [does delete on start](https://github.com/jupyterhub/dockerspawner/blob/d1e4841678708ae60035ea0691238636364733c9/dockerspawner/dockerspawner.py#L1040-L1048) `if DockerSpawner.remove`, so setting remove=True for this start will delete the previous container if there was one. The reasoning behind this is that `remove` config could have changed since the last shutdown, and it should take effect immediately, not after the _next_ shutdown and restart. So the only thing missing is _changing_ `spawner.remove` after startup. If you always set it to False after startup, then setting ‘remove’ in your profiles would mean “start a clean session” vs “reuse previous session”.

```python
class MyDockerSpawner(DockerSpawner):
    def stop(self):
        # never remove containers on stop, only (optionally) remove them on next start!
        self.remove = False
        return super().stop()

```

_However_

> Is there any consensus on this subject?

I think the best practice is to always use `remove = True` and _document_ what is persisted (e.g. user’s home directory) and what is not (e.g. the root Python environment). Then ask your users what it is that they want persisted that isn’t being persisted. Is it user-installed packages? If so, document creating environments in the home directory which will be persisted, etc.

---

_[View the full topic](https://discourse.jupyter.org/t/dockerspawner-container-deletion-by-user-choice/8024)._
