skip to Main Content

I have my docker-compose.yaml file like this:

version: "3"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - ./app:/app
    command: >
      sh -c "python manage.py runserver 0.0.0.0:8000"
      sh -c "python simple_script.py"
      

and the problem is that when i run docker-compose up it never reaches the second command ( sh -c "python simple_script.py" ) .

I think this is because the first command sh -c "python manage.py runserver 0.0.0.0:8000" never exits.

Is there a way to run two commands like this?

2

Answers


  1. You can write two commands in one line. like this –

    sh -c "python manage.py runserver 0.0.0.0:8000 && python simple_script.py"
    
    Login or Signup to reply.
  2. can you try this one:

    sh -c "python manage.py runserver 0.0.0.0:8000 & python simple_script.py"  
    

    In linux you can use & to run commands in background.
    You can use fg to get back to it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search