Running django migrate in docker

I am creating a Python + Django development environment using docker. I defined Dockerfile files and services in the docker-compose.yml containers for the web server (nginx) and the database (postgres) and the container that will run our application using uwsgi. Since this is a dev environment, I am mounting the application code from the host system, so I can easily edit it in my IDE.

I have a question where / how to execute the migrate command.

In case you do not know Django, the migrate command creates a database structure and then changes it as necessary to the project. I have seen people start migrations as part of the compose command command: python manage.py migrate && uwsgi --ini app.ini, but I don't want migrations to start every time the container is reloaded. I just want it to start once when I create containers and never start again until rebuild.

Where / how can I do this?

Edit: There is an open problem in the development team. If you're lucky, command containers will get support at one time. https://github.com/docker/compose/issues/1896

+4
source share
3 answers

RUN, , , .

CMD, , .

docker exec . , dockerfile docker-compose - , .

0

, . dobi - , ( : ).

: https://github.com/dnephin/dobi/tree/master/examples/init-db-with-rails. , , django.

migrate, . , docker-compose, .

0

docker exec -it container-name bash

Then you will get inside the container, and you will be able to run any command that you usually execute when working without using dockers.

-1
source

Source: https://habr.com/ru/post/1657510/


All Articles