Run multiple scripts in docker image

Viewed 18509

Hi i am wondering if it possible to run two scripts in same time automaticly on docker container start . First script have to run client application, and the second run server app as background.

3 Answers

As mentioned having multiple processes is not a suggested practice.

Nevertheless, in some scenarios is required to have multiple processes. In those cases the usual approach is to use a process manager like supervisor.

Docker's official stance on this has always been that it is best to only have a single service running in a container. Having said that, they also maintain very robust documentation outlying possible solutions for getting multiple services into a single container.

https://docs.docker.com/config/containers/multi-service_container/

A quick summary is essentially that when you have multiple services, you need to have some type of "init" process to act as a parent for all the services in the container.

There's two ways to do this:

  1. Have a shell script that runs each service as a background job.
  2. Launch a full init system inside the container and launch the services under this.

Both are problematic. The first because bash is not an init system, and you can end up with all kinds of headaches when it doesn't act like one. The second because an init system is a pretty heavy duty thing to put into a docker container.

Having said all that, the best solution is to split your services into two containers.

Related