我为图像创建了Dockerfile以便在FPM + Nginx上运行PHP7,但是我无法获得该图像以正确启动服务。
应该如何精确地做到这一点?
这是我目前正在做的事情:
CMD service php7-fpm start; \
service php7-fpm status; \
service nginx start; \
service nginx status
最佳答案
在管理多种服务时,您需要用户监督。
在您的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"]
administratord.conf
[supervisord]
nodaemon=true
[program:php7]
command=<command to start php7>
autostart=true
autorestart=true
<repeat for additional services>...
这将确保一旦一切开始容器就不会退出。请记住,Docker应该是一个进程环境,该进程在前台运行,而不是在后台作为服务运行。
关于php - 如何在Docker镜像上启动服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32232403/