DarVar
DarVar

Reputation: 18124

Docker launch 2 processes in the conatiner

New to Docker and I'm reading that a Dockerfile can only have 1 CMD.

So how do I start both my database server and application server? Something like:

CMD /root/database/bin/server run &
CMD /root/appserver/bin/server run &

Upvotes: 0

Views: 127

Answers (2)

Thomas Uhrig
Thomas Uhrig

Reputation: 31605

Docker can run as many processes as you want to. It is no problem to run a database and an application server in the same container. However, you can only run one command in your container, so this command must start all other processes and it must run as long as your container runs (if it stops, your container will stop).

So start a shell script which itself will start all other things:

CMD /run.sh

The shell script could look like this:

echo "Lets start up"

:: Run your database server in background
/root/database/bin/server run &

:: Run your app server (not in background to keep the container up)
/root/appserver/bin/server run

Upvotes: 1

Alister Bulman
Alister Bulman

Reputation: 35139

Docker can only start one process in a container - but that process can start whatever it likes.

Supervisord has been a popular choice to use that will then go on to star whatever else you want/need to.

Upvotes: 4

Related Questions