In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use Supervisor to manage multiple processes in Docker container". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Supervisor to manage multiple processes in Docker container".
By default, the docker container only runs a single process (the idea advocated by docker), but the project requires two services (php-fpm and nginx), so it requires third-party process management software. The more popular solution in docker is to use supervisor software to manage multiple processes.
Environment description
Build catalog
Tree demo/demo/ ├── conf │ ├── default.conf │ ├── nginx.conf │ ├── php-docker.conf │ ├── php.ini │ ├── php-www.conf │ └── supervisord.conf ├── Dockerfile └── src └── demo.tar.gz2 directory, 8 files
Code file
The src directory stores the project code archive demo.tar.gz # files generated by the jenkins CI tool.
Configuration file
The conf directory holds the configuration file nginx configuration file: default.conf # virtual host configuration document nginx.conf # nginx main configuration document php related configuration file: php.ini # php main configuration document php-docker.conf # php-fpm configuration php-www.conf # php-fpm document supervisor configuration file: supervisord.conf # supervisor configuration document
Nginx and php profiles can be configured by default or according to actual requirements.
If you need a php-fpm configuration file, you can obtain the configuration file in the container, such as the www.conf file, by using the command:
Docker run-rm php:5.6-fpm cat / usr/local/etc/php-fpm.d/www.conf > >. / my.conf
Let's focus on Dockerfile and supervisord.
Operation steps
Let's take a look at Dockerfile first.
Cat demo/Dockerfile# uses custom project base image demo-base:0.0.1FROM demo-base:0.0.1MAINTAINER dongnan # # phpCOPY conf/php.ini / usr/local/etc/php/php.iniCOPY conf/php-www.conf / usr/local/etc/php-fpm.d/www.confCOPY conf/php-docker.conf / usr/local/etc/php-fpm.d/docker.conf# nginxCOPY conf/nginx.conf / etc/nginx/nginx.confCOPY conf/default .conf / etc/nginx/conf.d/default.conf# supervisorRUN mkdir-p / var/log/supervisor\ & & mkdir-p / var/log/phpCOPY conf/supervisord.conf / etc/supervisor/supervisord.conf# code into the nginx root directory The directory location should be consistent with the virtual host configuration. # ADD instruction automatically unzips the package, and the RUN instruction executes permission setting command WORKDIR / var/www/ADD src/demo.tar.gz / var/www/RUN chown-R www-data.www-data. # statement portEXPOSE 8 directory cmdCMD ["/ usr/bin/supervisord", "- c", "/ etc/supervisor/supervisord.conf"]
Supervisor profile
Cat demo/conf/ dictord.confession] nodaemon=truepidfile=/var/run/supervisord.pidlogfile=/var/log/supervisor/ principord.log [program: nginx] command=/usr/sbin/nginx-g "daemon off;" [program:php-fpm] command=/usr/local/sbin/php-fpm-c / usr/local/etc/php/php.ini-y / usr/local/etc/php-fpm.conf-F
Supervisor configuration parameters
Nodaemon=true # run the supervisord main process pidfile/logfile # in the foreground specify the file location [program:xxx] # define the startup command of the application command # program managed by supervisord, you need to use the absolute path nginx-g "daemon off;" # run nginx php-fpm in the foreground.-F # run php-fpm in the foreground
Build a project image
Cd demo/docker build-t demo-project:0.0.1 .Sending build context to Docker daemon 3.2 mb# omitted.... Successfully built ai43125ed1u0
Verify the mirror image
# create container docker run-d-- name test demo-project:0.0.19a40982510xxxxxxx9d227d3456b2261c6451109020a# container process docker inspect-- format= "{{State.Pid}}" test30878# nginx and php-fpm processes managed by supervisor pstree 30878supervisord ─┬─ nginx ─── 2* [nginx] └─ php-fpm ─── 2* [php-fpm] # can also be viewed using the command `docker top xxx`, but the output is too much and the Wechat article breaks seriously. Summary
Finally, let's summarize the knowledge points in the article.
The role of the basic image is to provide support for the project image, and add the project code to the basic image to complete the construction of the project image.
Use supervisor to run and manage multiple processes in the container, and supervisord will be the first process in the container.
After supervisord runs, the managed process starts as a child process of supervisord, monitors the status of the child process, and automatically restarts if it exits abnormally.
Thank you for reading, the above is the content of "how to use Supervisor to manage multiple processes in Docker container". After the study of this article, I believe you have a deeper understanding of how to use Supervisor to manage multiple processes in Docker container, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.