Data Loss when you restart Pods

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

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.

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

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:**

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