在一个Docker容器中启动两个服务器

我用我的所有configuration创build了一个Dockerfile

最后我想从python server.py运行一个python服务器,也从npm start一个节点服务器

因为我可以有一个CMDENTRYPOINTdocker run执行时,我怎么能启动这两个服务器?

docker推荐的处理这种情况的方式是什么?

当你想在一个容器中运行多个进程时,你可以使用supervisord – 就像在你的情况npmpython server

查看supervisord的文档以获取更多信息。

我只是select一些重要的部分。

  • 1,您需要为docker镜像安装supervisord

就像是:

 CentOS: `yum install supervisor` Ubuntu: `apt-get install -y supervisor` 
  • 2,将supervisord( supervisord.conf )的configuration拷贝到docker镜像。

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

在你的情况supervisord.conf应该看起来像下面的例子(未testing):

 [supervisord] nodaemon=true [program:npm] command=npm start [program:python] command=python server.py 

并在Dockerfile中运行supervisord作为CMD命令:

 ... # install supervisord # copy supervisord configuration ... # run supervisord CMD ["/usr/bin/supervisord"]