Home > Software engineering >  Docker-compose cant reach second command
Docker-compose cant reach second command

Time:01-31

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?

CodePudding user response:

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.

CodePudding user response:

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"
  •  Tags:  
  • Related