Reputation: 10349
I have a docker compose file that looks like:
version: "3" services: redis: image: 'redis:3.2.7' # command: redis-server --requirepass redispass postgres: image: postgres:9.6 ports: - "5432:5432" environment: - POSTGRES_USER=airflow - POSTGRES_PASSWORD=airflow - POSTGRES_DB=airflow # - PGDATA=/var/lib/postgresql/data webserver: image: airflow:develop depends_on: - postgres ports: - "8080:8080" command: - webserver
After I run docker-compose up
I see all the services started and seemingly working well. My webserver
service connects to postgres with the following sqlalchemy connection string: postgresql+psycopg2://airflow:airflow@postgres/airflow
Whenever I kill the composition (with ctrl-c
or docker-compose stop
) and then restart it, the data in postgres seems to persist. The reason I believe it persists is because my webserver starts with data from the previous session.
I read the docs for the postgres docker image and found the PGDATA
environment variable. I tried to force set it to the default (as seen in the commented line in my docker compose file, but that didn't help. I'm not sure how else to debug why data seems to be persisting between container starts.
How can I force my postgres container to start fresh with each new initialization?
Upvotes: 2
Views: 4966
Reputation: 10185
Your data was persisted because you did not destroy postgres
container. You used docker-compose stop
which only hibernate containers. Use docker-compose down
instead. It completely destroys containers (but not images).
Upvotes: 9