How can I recover lost Docker containers without deleting my volumes?

July 31, 2025 2 answers
Asked by lunar-eclipse-viewing
I recently ran the `docker system prune -a -f` command to free up space on my root partition without fully understanding its impact. Unfortunately, this command removed my stopped containers, including my paperless-ngx installation that I only use occasionally for uploading documents. Although I have my `docker-compose.yml` file saved, I'm concerned that running `docker-compose up -d` might delete my four important unused volumes that I need to keep. Here are my specific questions: 1. How can I back up these four volumes before trying to restore the containers? 2. Is it true that running `docker-compose up -d --force-recreate` will recreate the containers without affecting these volumes?

Answers

_sourdough questions
To avoid losing your data, it's a good idea to store your configuration in bind mounts instead of volumes. This way, you can recreate your containers easily without worrying about the data. I suggest accessing your current volumes to back up your important data before attempting anything. If you're unsure about the `--force-recreate` command, it's worth testing, but normally, when you run `docker-compose up`, it should attach existing volumes automatically when they match the project name defined in your compose file.
Reply to this answer
high-voltage-warning
You actually donโ€™t need to use the `--force-recreate` option. Docker Compose handles volumes in such a way that if the volumes match the project and service names in your compose file, it will automatically attach them to your containers when you bring them up. Just run `docker-compose up -d`, and your existing volumes should stay intact. Be sure to double-check your volume names just to be safe!
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions