Start two servers in one docker container
docker, dockerfile
Solution
You can use `supervisord` when you want to run multiple processes in one container - like in your case `npm` and `python server`.
Check documentation for supervisord for more information.
I just pick some important parts.
- 1, You will need to install supervisord for docker image
Something like:
CentOS: `yum install supervisor`
Ubuntu: `apt-get install -y supervisor`
- 2, copy configuration for supervisord (`supervisord.conf`) to docker image .
`COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf`
In your case `supervisord.conf` should looks like example below (not tested) :
[supervisord]
nodaemon=true
[program:npm]
command=npm start
[program:python]
command=python server.py
and run `supervisord` as `CMD` command in Dockerfile:
...
# install supervisord
# copy supervisord configuration
...
# run supervisord
CMD ["/usr/bin/supervisord"]
Problem
I have created a `Dockerfile` with all of my configurations. At the end I want to run one python server from `python server.py` And also a node server from `npm start` Because I can have one `CMD` or `ENTRYPOINT` how can I start both these two servers when `docker run` executed? What is the docker recommended way to handle these kind of situations?