使用Docker-Compose,如何执行多个命令

发布于 2021-02-01 13:09:26

我想做这样的事情,我可以依次运行多个命令。

db:
  image: postgres
web:
  build: .
  command: python manage.py migrate
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - db
关注者
0
被浏览
98
1 个回答
  • 面试哥
    面试哥 2021-02-01
    为面试而生,有面试问题,就找面试哥。

    想通了,使用 bash -c

    例:

    command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    

    多行中的相同示例:

    command: >
        bash -c "python manage.py migrate
        && python manage.py runserver 0.0.0.0:8000"
    

    要么:

    command: bash -c "
        python manage.py migrate
        && python manage.py runserver 0.0.0.0:8000
      "
    


推荐阅读
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看