Docker uses supervisor to manage multiple processes

Source: Internet
Author: User
Tags docker run

Docker uses supervisor to manage multiple processes


Docker digression:

CENTOS7 Installing Supervisor:

Source Code Compilation Installation:

Download source files: supervisor-3.3.1.tar.gz:https://pypi.python.org/pypi/supervisor
 installation:[[email protected] src]# tar -zxf  supervisor-3.3.1.tar.gz[[email protected] src]# cd supervisor-3.3.1/[[email protected ] supervisor-3.3.1]# python setup.py install Check for installation success: Login to python console input import supervisor   See if [[email protected] supervisor-3.3.1]# pythonpython 2.7.5  can be loaded successfully (default,  sep 15 2016, 22:37:39)  [GCC 4.8.5 20150623  (red hat 4.8.5-4 )] on linux2type  "Help",  "copyright",  "credits"  or  "license"  for  More information.>>> import supervisor>>> 
Build configuration file: [[email protected] supervisor-3.3.1]# mkdir /etc/supervisor[[email protected]  supervisor-3.3.1]# echo_supervisord_conf > /etc/supervisor/supervisord.conf [[ email protected] supervisor-3.3.1]# grep -e -v  ' ^;|^$ '  /etc/supervisor/ supervisord.conf[unix_http_server]file=/tmp/supervisor.sock   ;  (the path to  the socket file) [supervisord]logfile=/tmp/supervisord.log ;  (main log file ;d efault  $CWD/supervisord.log) logfile_maxbytes=50mb        ;   (MAX MAIN LOGFILE BYTES B4 ROTATION;DEFAULT 50MB) logfile_backups=10            ;  (num of main logfile  ROTATION BACKUPS;DEFAULT 10) loglevel=info                 ;  (Log level;default info; others: debug,warn,trace) pidfile=/tmp/ supervisord.pid ;  (supervisord pidfile;default supervisord.pid) nodaemon=false                ;  (start in  Foreground if true;default false) minfds=1024                   ;  (min. avail startup file  descriptors;default 1024) minprocs=200                  ;  (min. avail process descriptors;default  ) [Rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_ Rpcinterface[supervisorctl]serverurl=unix:///tmp/supervisor.sock ; use a unix:// url   for a unix sockeT 


Start service: [[email protected] tmp]# supervisord-c/etc/supervisor/supervisord.conf Close service: [[email protected] tmp]# Supervisorctl Shutdownshut down View status: [[email protected] tmp]# supervisorctl status Start or stop a service: Supervisorctl Stop|start Program_name


Yum Install directly:

RPM-UVH Https://mirrors.ustc.edu.cn/fedora/epel/7/x86_64/e/epel-release-7-8.noarch.rpmyum update;yum-y Install Supervisorcat/etc/supervisord.confsupervisord-c/etc/supervisord.conf



Description

The Docker container opens a single process at startup, such as an SSH or Apache daemon service. But we often need to open multiple services on a machine, this can have many methods, the simplest is to put multiple startup commands in a startup script, start the script directly, and the installation process management tool

Use the Process management tool supervisor to manage multiple processes in a container. Use Supervisor to better control, manage, and restart the processes we want to run

Here we demonstrate how the SSH and Tomcat services are used in the container



Configuration:

     first create Dockerfile file:

[[email protected] shencj]# vim dockerfile # centos:ssh## version                0.0.1 FROM  centosmaintainer shencj  "[email protected]"   #sshRUN  yum install -y  Openssh openssh-server openssh-clientsrun mkdir /var/run/sshdrun ssh-keygen -t  rsa -f /etc/ssh/ssh_host_rsa_keyrun ssh-keygen -t dsa -f /etc/ssh/ssh _host_dsa_keyrun sed -i  ' s/#UseDNS  yes/usedns no/g '  /etc/ssh/sshd_configrun  sed -i  ' s/gssapiauthentication yes/gssapiauthentication no/g '  /etc/ssh/sshd_ configrun /bin/echo  ' root:123456 '  |chpasswdRUN /bin/sed -i  ' s/.*session.* Required.*pam_loginuid.so.*/session optional pam_loginuid.so/g '  /etc/pam.d/sshdrun /bin/ echo -e  "Lang=\" en_US. Utf-8\ ""  > /etc/default/local  #tomcatADD  apache-tomcat-7.0.41.tar.gz /usr/local/src/copy  jdk-7u80-linux-x64.rpm /usr/local/src/WORKDIR /usr/local/src/RUN rpm -ivh  jdk-7u80-linux-x64.rpmenv java_home /usr/java/jdk1.7.0_80env path  $PATH: $JAVA _home/binenv  classpath .: $JAVA _home/jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar#run java  -versionrun mkdir -p /usr/local/toolsrun cp -r apache-tomcat-7.0.41 / usr/local/tools/tomcat7_8080  #supervisorRUN  rpm -uvh https://mirrors.ustc.edu.cn/fedora/ epel/7/x86_64/e/epel-release-7-8.noarch.rpmrun yum update;yum -y install  supervisorrun mkdir -p /etc/supervisor/copy supervisord.conf /etc/supervisor/  Expose 22 8080cmd supervisord -c /etc/supervisor/supervisord.conf#cmd [" Supervisord ","-C ","/etc/supervisor/supervisoRd.conf "] 
[[email protected] shencj]# vim supervisord.conf  [unix_http_server]file=/var/ run/supervisor/supervisor.sock   ;  (The path to the socket file)  [supervisord]logfile=/var/run/supervisor/supervisord.log ;  (Main log file;default   $CWD/supervisord.log) logfile_maxbytes=50mb        ;  (max  MAIN LOGFILE BYTES B4 ROTATION;DEFAULT 50MB) logfile_backups=10            ;  (num of main logfile rotation  BACKUPS;DEFAULT 10) loglevel=info                 ;  (Log level;default info; others: debug,warn,trace) pidfile=/var/run/supervisor/supervisord.pid ;  (supervisord pidfile;default supervisord.pid ) NODAEMON=TRUE  &Nbsp;            ;  (start in  Foreground if true;default false) minfds=1024                   ;  (min. avail startup file  descriptors;default 1024) minprocs=200                  ;  (min. avail process descriptors;default   [rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_) Main_rpcinterface [supervisorctl]serverurl=unix:///var/run/supervisor/supervisor.sock ; use  a unix:// url  for a unix socket [program:sshd]command=/usr/sbin /sshd -d [program:tomcat]command=/usr/local/tools/tomcat7_8080/bin/catalina.sh run

Note :

Serverurl=unix:///var/run/supervisor/supervisor.sock: This proposal does not modify

Nodaemon=true: Set to True

command=/usr/local/tools/tomcat7_8080/bin/catalina.sh Run: This must be written (Supervisor Management Tomcat must boot like this, Other ways seem to have problems ), refer to:http://serverfault.com/questions/425132/controlling-tomcat-with-supervisor

To create a mirror:

[email protected] shencj]# Docker build-t shencj/centos-ssh-tomcat:v1.


To run the container:

[email protected] shencj]# Docker run-d--name ssh-tomcat--restart=always-p 4426:22-p 82:8080 SHENCJ/CENTOS-SSH-TOMCA T:v1cc8006c07f6c703c476c69ecc3699f0c9a1e5f456949e65a8e92b55dafa8be1e[[email protected] shencj]#


To view containers:     

[[email protected] shencj]# docker ps -acontainer id         IMAGE                          COMMAND                   CREATED              STATUS               PORTS                                          NAMEScc8006c07f6c         shencj/centos-ssh-tomcat:v1    "/bin/sh -c  ' Supervis"     56 seconds ago      up 54 seconds        0.0.0.0:4426->22/tcp, 0.0.0.0:82->8080/tcp   ssh-tomcat


Login Container:

[[email protected] shencj]# ssh localhost -p 4426[email protected] ' s  password: [[email protected] ~]# ps -ef uid          PID   PPID  C STIME TTY           time cmdroot          1       0  0 03:56 ?         00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisor/ supervisord.confroot          7       1  0 03:56 ?        00:00:00 /usr /sbin/sshd -droot          8       1  3 03:56 ?        00:00:03 /usr/java/jdk1.7.0_80/bin/java - djava.util.logging.config.file=/usr/local/tools/tomcat7_8080/conf/logging.properties - djava.util.logging.manager=org.aparoot         30       7  0 03:58 ?         00:00:00 sshd: [email protected]/0root         32      30  0 03:58 pts/0    00:00:00 - Bashroot         45     32  0  03:58 pts/0    00:00:00 ps -ef[[email protected] ~]#  supervisorctl statussshd                              running   pid 7, uptime 0:02:58tomcat                             running   pid 8, uptime 0:02:58


Access Tomcat:

http://ip:82

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "border=" 0 "style=" Background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650) this.width =650; "Src=" Http://s5.51cto.com/wyfs02/M00/88/A1/wKiom1f9vTSQ647GAAFbt8Ui09M497.png-wh_500x0-wm_3-wmp_4-s_ 2836851935.png "title=" Qq20161012123324.png "alt=" wkiom1f9vtsq647gaafbt8ui09m497.png-wh_50 "/>













This article is from the "See" blog, please be sure to keep this source http://732233048.blog.51cto.com/9323668/1861018

Docker uses supervisor to manage multiple processes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.