Home > database >  How do I run two commands as part of a single docker-compose "command"?
How do I run two commands as part of a single docker-compose "command"?

Time:01-28

I’m using Docker v. 20.10.12. I have set up this container in my docker-compose file …

  web:
    restart: always
    build: ./my-web
    ports:
      - "3000:3000"
    expose:
      - '3000'
    env_file: ./my-web/.docker_env
    command: rm -f /app/tmp/pids/*.pid && foreman start -f Procfile.hot
    volumes:
    - ./my-web/:/app
    depends_on:
      - db

When I start using “docker-compose up”, the above container always displays this message

my-web-1 exited with code 0

There is no other info before that. However, if I change the command to be

command: tail -F anything

And then log in to the docker container, I can run

rm -f /app/tmp/pids/*.pid && foreman start -f Procfile.hot

just fine without an errors. How would I run that as part of starting up my Docker container without having to do the manual steps from above?

CodePudding user response:

You can do

command: /bin/sh -c "rm -f /app/tmp/pids/*.pid && foreman start -f Procfile.hot"

CodePudding user response:

Try to put all your commands inside an external sh file. in docker-compose use

command: /bin/sh -c "yourshfile.sh"

  •  Tags:  
  • Related