We created an application that consists of microservices, and that doesn't have a persistent state – the application is empty on every restart. Fixing this is simple: map the persistent volume to a folder of the container. Since no one microservice of our application keeps the data in files, but the PostgreSQL database does, we only need to attach a folder to a database container. Copy docker-compose.test.yml to docker-compose.prod.yml and add the following changes:
services:
db:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- database_data:/var/lib/postgresql/data
# other containers definition
volumes:
database_data:
driver: local
We attached a volume with the name database_data to the /var/lib/postgresql/data path...