如何在Docker镜像上启动服务?

我为图像创build了一个Dockerfile来在FPM + Nginx上运行PHP7,但是我无法获得正确启动服务的图像。

这应该如何完成?

以下是我目前正在做的部分:

CMD service php7-fpm start; \ service php7-fpm status; \ service nginx start; \ service nginx status 

当pipe理多个服务时,你会想要用户supervisord。

在你的Dockerfile中。

 Additional commands... RUN apt-get update && apt-get install -y supervisor ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf Additional commands... CMD ["/bin/supervisord", "-c /etc/supervisor/conf.d/supervisord.conf"] 

supervisord.conf

 [supervisord] nodaemon=true [program:php7] command=<command to start php7> autostart=true autorestart=true <repeat for additional services>... 

这将确保一旦一切都开始,容器不会退出。 记住Docker 应该是一个单一的进程环境,这个进程在前台运行,而不是后台运行。

你需要一个进程pipe理器,比如主pipe,s6,守护进程或者任何其他的

例如,请参阅主pipe的文档

https://docs.docker.com/articles/using_supervisord/