Reputation: 165
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.
Upvotes: 4
Views: 32240
Reputation: 10064
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.
Upvotes: 7
Reputation: 5829
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:
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.
Upvotes: 4
Reputation: 817
You can use CMD
in your Dockerfile
and use command &
to run two command in parallel:
CMD server_command & client_command
(where server_command
is the command used to start the server and client_command
is the command used to start the client)
Upvotes: 9