How do I execute multiple commands in command in a docker-compose.yml file?

< H1 > problem description < / H1 >

I want to use docker to package my Django project, and then use docker-compose for service orchestration to run the database needed by the Django project. Suppose the content in docker-compose.yml is as follows:

version: "3"
services:
    web:
        image: my_project:latest
        ports:
          - 8000:8000
        command: python3 manage.py runserver 0.0.0.0:8000
        depends_on:
          - postgres
    postgres:
        image: postgres

before running python3 manage.py runserver 0.0.0.0 code 8000 , I want to use python3 manage.py migrate to Synchronize the structure of the database. Where should I add this order?


if there is another longer script that needs to be written on a new line, write it as follows

command: python3 manage.py migrate && python3 manage.py runserver 0.0.0.0:8000
Menu