如何在 Docker 图像上启动服务?
How to startup up services on a Docker image?
我已经在 FPM + Nginx 上为 运行 PHP7 的图像创建了 Dockerfile,但我无法获取图像以正确启动服务。
具体应该怎么做?
这是我目前正在做的部分:
CMD service php7-fpm start; \
service php7-fpm status; \
service nginx start; \
service nginx status
您需要一个进程管理器,例如 supervisor、s6、daemontools 或任何其他
例如,请参阅主管文档
管理多项服务时,您需要使用 supervisord。
在你的Docker文件中。
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 应该 是一个进程环境,该进程 运行 在前台而不是后台作为服务。
我已经在 FPM + Nginx 上为 运行 PHP7 的图像创建了 Dockerfile,但我无法获取图像以正确启动服务。
具体应该怎么做?
这是我目前正在做的部分:
CMD service php7-fpm start; \
service php7-fpm status; \
service nginx start; \
service nginx status
您需要一个进程管理器,例如 supervisor、s6、daemontools 或任何其他
例如,请参阅主管文档
管理多项服务时,您需要使用 supervisord。
在你的Docker文件中。
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 应该 是一个进程环境,该进程 运行 在前台而不是后台作为服务。