D
D
Dagcrag2017-06-03 23:52:18
PostgreSQL
Dagcrag, 2017-06-03 23:52:18

docker-compose postgresql initialization?

Today I decided to deploy my project to docker. The simplest application on django, in which, by pressing buttons, data is pulled out of tables, written to others, etc.
I go into the project folder, naturally there are dockerfile, docker-compose.yml files. So, I enter the docker-compose up command. An environment is created, modules django, psycopg2 are installed in pip. Then makemigrations and migrate. As a result, I get a finished project, the server starts up and everything works. But the database is empty.
How can I initialize the database values ​​in the docker and save them so that I can drop the folder with the project and when I type docker-compose up, everything happens the same + the database is initialized with the base values. I understand that they usually do it this way, or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BannedOnStackoverflow, 2017-06-04
@BannedOnStackoverflow

To save data not only inside the docker container, but also in the local folder with the project, you need to create a volume in docker-compose.yml and mount it to the local folder, and in the service with postgre do volumes_from

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question