Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19k points)
edited by

I have been trying to run multiple commands:

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

Can anyone help me with this?

Thanks

2 Answers

0 votes
by (33.1k points)

You can simply use bash -c.

For example:

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

The same example in multi-lines:

command: >

    bash -c "python manage.py migrate

    && python manage.py runserver 0.0.0.0:8000"

Or:

command: bash -c "

    python manage.py migrate

    && python manage.py runserver 0.0.0.0:8000

  "

Hope this answer helps you!

Also, if you are eager to learn more about docker then you can visit Docker Tutorial and join Docker Certification.

0 votes
by (107k points)

In order to run multiple commands in docker at once, use /bin/bash -c with a semicolon ';'

For example: 

docker run image /bin/bash -c "cd /some/path; python a.py"

In this case, the second command (python) will be executed only if the first command (cd) returns no error or exit status. To avoid this use '&&' instead of ';' (semi-colon)

For example:

 docker run image /bin/bash -c "cd /some/path && python a.py"

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...