0

Im learning Docker and for test purposes Im running a Django App in it. Everything is OK and running. But now i want to use database(Postgres) in my containerised architecture.

As we know, If a container stops, All data will be reseted and because of that I can't put my database in container, Right? Im confused about this.

Should I run database server outside of container? Then how App inside container should talk with that? Or I have to run database service in the container and read database dump files from external source?

Im confused about architecture! Containers are just for Apps and codes no just database servers? Or I can use database inside the container? I love containers idea and i want to do my project as a package that runs everywhere... But when im using database server, is this possible?

Fcoder
  • 9,066
  • 17
  • 63
  • 100
  • 1
    If a container stops, it can be restarted from it's existing state. If a container is removed then you lose the data. But [volumes are how you should be persisting storage](https://stackoverflow.com/questions/18496940/how-to-deal-with-persistent-storage-e-g-databases-in-docker#20652410) so even a new container can use the same data. – Matt Nov 19 '17 at 03:35

1 Answers1

0

The data will persist as long as you don't destroy the container. You'll likely want to use docker-compose to orchestrate the containers/networking etc.

So running docker-compose stop will halt the container, but the data will persist the next time you run docker-compose up. However if you run docker-compose down, this will destroy the volumes and data will be lost.

DivXZero
  • 601
  • 1
  • 7
  • 17
  • 1
    `docker-compose down` won't destroy volumes defined in the compose file, only ephemeral volumes created for images that are built with defined `VOLUME`. – Matt Nov 19 '17 at 04:15