0

I'm using a Dockerfile that ends with a CMD ["/start.sh"]:

#!/bin/bash
service ssh start
/usr/bin/node /myApp/app.js

if for some reason i need to kill the node process, the ssh server is being closed as well (forces me to reboot the container to reconnect).

Any simple way to avoid this behavior?

Thank You.

TesterBoy
  • 15
  • 4
  • I would just not run the ssh daemon. Treat the container the same way you'd treat the identical `node app.js` process on the host without Docker. – David Maze Dec 30 '19 at 18:20

1 Answers1

0

The container exits as soon as main process of the container exits. In your case, the main process inside the container is start.sh shell script. The start.sh shell script is starting the ssh service and then running the nodejs process as child process. Once the nodejs process dies, the shell script exits as well and so the container exits. So what you can do is to put the nodejs process in background.

#!/bin/bash
service ssh start
/usr/bin/node /myApp/app.js &
# Need the following infinite loop as the shell script should not exit
while do:
   sleep 2
done

I DO NOT recommend this approach though. You should have only a single process per container. Read the following answers to understand why -

Running multiple applications in one docker container

If you still want to run multiple processes inside container, there are better ways to do it like using supervisord - https://docs.docker.com/config/containers/multi-service_container/

Shashank V
  • 10,007
  • 2
  • 25
  • 41
  • Thank you for the information! I just need the ssh for troubleshooting purposes as i have no other means of connecting to this remote container. – TesterBoy Dec 30 '19 at 18:59