If you want to launch a migration while the application is running, use docker exec -it name-of-container bash
to open a shell in the running container and execute the command.
If you need to run the migration before the first launch of the application, run docker-compose run name-of-service bash
, run the command that initialize the database, exit and launch docker-compose
normally.
If you want to run the migrations before each launch of the application, you could write a shell script that performs both actions (migration, then launch the application) copy it in the image and call it as your default command.
For the 2 first paragraphs, you could also directly launch the migration command instead of running bash