I have a main service in my docker-compose
file that uses postgres
's image and, though I seem to be successfully connecting to the database, the data that I'm writing to it is not being kept beyond the lifetime of the container (what I did is based on this tutorial).
Here's my docker-compose
file:
main:
build: .
volumes:
- .:/code
links:
- postgresdb
command: python manage.py insert_into_database
environment:
- DEBUG=true
postgresdb:
build: utils/sql/
volumes_from:
- postgresdbdata
ports:
- "5432"
environment:
- DEBUG=true
postgresdbdata:
build: utils/sql/
volumes:
- /var/lib/postgresql
command: true
environment:
- DEBUG=true
and here's the Dockerfile I'm using for the postgresdb
and postgresdbdata
services (which essentially creates the database and adds a user):
FROM postgres
ADD make-db.sh /docker-entrypoint-initdb.d/
How can I get the data to stay after the main
service has finished running, in order to be able to use it in the future (such as when I call something like python manage.py retrieve_from_database
)? Is /var/lib/postgresql
even the right directory, and would boot2docker
have access to it given that it's apparently limited to /Users/
?
Thank you!
sqlalchemy
(that's what I'm using)? I believe I'm committing the changes "manually" --that is, by runningpython manage.py insert_into_database
within the main service and letting that commit to Postgres (which worked before I started using Docker). Is this what you mean? – aralar Apr 24 '15 at 16:07