# Data Loss when you restart Pods

**URL:** <https://community.okteto.com/t/data-loss-when-you-restart-pods/421>\
**Category:** How Do I?\
**Created:** [December 14, 2022, 9:11am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421 "2022-12-14T09:11:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hebifa.Rafiki](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/hebifa.rafiki/32/182_2.png) [@Hebifa.Rafiki](https://community.okteto.com/u/Hebifa.Rafiki)\
**Post date:** [December 14, 2022, 9:11am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421/1 "2022-12-14T09:11:08Z")

</div>

What is the best way to prevent loss of data whenever i restart the pods.

Each time i restart/rebuild the pods to reflect code changes i loos all the data in the database and i have to them in.

Please advice on the best practice

---

<div class="post-metadata">

**Author:** ![ramiro](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/ramiro/32/6_2.png) [@ramiro](https://community.okteto.com/u/ramiro)\
**Post date:** [December 14, 2022, 9:16am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421/2 "2022-12-14T09:16:36Z")

</div>

You should configure your database service to store the DB data on a persistent volume. That way it’ll survive being restarted.

How are you defining your application? If you share your manifest, we can make some suggestions.

---

<div class="post-metadata">

**Author:** ![Hebifa.Rafiki](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/hebifa.rafiki/32/182_2.png) [@Hebifa.Rafiki](https://community.okteto.com/u/Hebifa.Rafiki)\
**Post date:** [December 14, 2022, 10:47am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421/3 "2022-12-14T10:47:22Z")

</div>

I did that be choosing an external volume in docker-compose file.

There are times it does not delete, there are times it deletes all the data

I am not sure why that behaviour

---

<div class="post-metadata">

**Author:** ![Hebifa.Rafiki](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/hebifa.rafiki/32/182_2.png) [@Hebifa.Rafiki](https://community.okteto.com/u/Hebifa.Rafiki)\
**Post date:** [December 14, 2022, 10:49am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421/4 "2022-12-14T10:49:21Z")

</div>

Below is my docker compose file.

wserver: ## Nodejs Back-end  
depends\_on:  
- mongodb  
build: ./www  
restart: unless-stopped  
env\_file: .env  
ports:  
- 8090:8090  
environment:  
- DB\_HOST=\*\*\*\*\*\*\*\*  
- DB\_USER=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
- DB\_PASSWORD=\*\*\*\*\*\*\*\*\*\*\*\*  
- DB\_NAME=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
- DB\_PORT=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
stdin\_open: true  
tty: true

grace: ## Angular Front-End  
depends\_on:  
- wserver  
build: ./portal  
restart: unless-stopped  
env\_file: .env  
ports:  
- 4201:4201

**volumes:**  
\*\* mongodb-data:\*\*

---

<div class="post-metadata">

**Author:** ![ramiro](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/ramiro/32/6_2.png) [@ramiro](https://community.okteto.com/u/ramiro)\
**Post date:** [December 19, 2022, 1:41am UTC](https://community.okteto.com/t/data-loss-when-you-restart-pods/421/5 "2022-12-19T01:41:21Z")

</div>

Can you add the definition for your mongodb service? That’s the one that needs to be configured with a volume.
