1

I run that:

docker run -it --restart always  --net=host myImage /bin/bash 

And I stay interactive then I run (inside the docker container)

/start.sh 

and everything is ok

My idea is to run /start.sh directly with docker run command

I tried that:

docker run -it --restart always  --net=host myImage /bin/bash -c "/start.sh"

Which seems to work, but once the start.sh finishes tasks, docker quits the interactive mode

start.sh only contains starting service

service apache start;
service mysql start;
pm2 start /chat.js;
6
  • This is very common problem that everyone bumps into when starting with docker. The way you are trying to do it makes your script run as PID 1 and after it stops, the container stops too. This happens because containers are up & running as long as PID 1 is running.
    – tgogos
    Jun 29, 2018 at 10:35
  • In the Dockerfile reference there is a section that describes how you can run a starter script and then pass the Unix signals to a different executable by using exec "$@". The idea here is that, this executable will be responsible to catch the signals and gracefully stop all the services that you are running.
    – tgogos
    Jun 29, 2018 at 10:40
  • You can also take a look at this: Docker container will automatically stop after “docker run -d” where tail -f /dev/null is proposed to keep the container running.
    – tgogos
    Jun 29, 2018 at 10:48
  • Understand the issue, but cannot really understand why there is no simple solution for such basic and common task
    – yarek
    Jun 29, 2018 at 10:52
  • Would it work with tail -f /dev/null & My goal is to have access to the console
    – yarek
    Jun 29, 2018 at 10:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.