<p>I noticed that you have the <code>docker run</code> command with <code>--rm</code> option. In the <a href="https://docs.docker.com/engine/reference/run/#clean-up---rm" rel="nofollow noreferrer">Docker docs</a> it says:</p>
<blockquote>
<p>If you set the --rm flag, Docker also removes the anonymous volumes associated with the container when the container is removed. This is similar to running docker rm -v my-container</p>
</blockquote>
<p>Perhaps this is why the volumes are being deleted?</p>

CC BY-SA 4.0
2020-12-04T15:37:59.250Z
2020-12-04T15:37:59.250Z
migueldavid
<p>No, docker does not automatically prune networks or images. That is left to the user to implement with their own tooling or scripting. It is possible for docker-compose to remove networks, but only when running a <code>docker-compose down</code>, and that doesn't remove networks. You'll need to search your own environment to see what you have running that performs a prune.</p>

CC BY-SA 4.0
2020-12-04T15:40:39.107Z
2020-12-04T15:40:39.107Z
BMitch
<p>I have a <a href="https://framagit.org/Nautigsam/kube-selfhost/-/blob/master/ansible/roles/backup-source/templates/backup_script.j2" rel="nofollow noreferrer">script</a> which performs backup of several docker volumes during the night.</p>
<p>It starts by stopping the containers that use these volumes, then it creates a new container with all the volumes mounted and back them up with borg. Finally it restarts the containers.</p>
<p>Sometimes the scripts runs into weird issues, like a container can not start because its image or a network it uses is missing. Is it possible that docker daemon prunes them while my backup script is running? How can I disable it?</p>
<p>I could not see anything in daemon logs.</p>

CC BY-SA 4.0
2020-12-03T13:34:30.353Z
I added a link to the script. This is only a jinja2 template but It is enough to understand what the script is doing.
Notiggsam
<docker>
Docker prunes image and networks by itself
Notiggsam
# Docker prunes image and networks by itself

(Asked by: username_0 on 2020-11-29)

I have a [script](https://framagit.org/Nautigsam/kube-selfhost/-/blob/master/ansible/roles/backup-source/templates/backup_script.j2) which performs backup of several docker volumes during the night.

It starts by stopping the containers that use these volumes, then it creates a new container with all the volumes mounted and back them up with borg. Finally it restarts the containers.

Sometimes the scripts runs into weird issues, like a container can not start because its image or a network it uses is missing. Is it possible that docker daemon prunes them while my backup script is running? How can I disable it?

I could not see anything in daemon logs.

**Tags:** docker

> **Comments:**
> **username_0**: I added a link to the script. This is only a jinja2 template but It is enough to understand what the script is doing.  

---

## 2 answers

### Answer by username_1 on 2020-12-04. Score: 1

I noticed that you have the `docker run` command with `--rm` option. In the [Docker docs](https://docs.docker.com/engine/reference/run/#clean-up---rm) it says:

> If you set the --rm flag, Docker also removes the anonymous volumes associated with the container when the container is removed. This is similar to running docker rm -v my-container

Perhaps this is why the volumes are being deleted?


---

### Answer by username_2 on 2020-12-04. Score: 0

No, docker does not automatically prune networks or images. That is left to the user to implement with their own tooling or scripting. It is possible for docker-compose to remove networks, but only when running a `docker-compose down`, and that doesn't remove networks. You'll need to search your own environment to see what you have running that performs a prune.


---

