28-案列2:使用Supervisor管理容器多进程
1.容器里安装supervior,进入到容器中
[root@ff769b402f81 ~]# yum install supervisor -y
2.修改配置supervisord文件,nodaemon=false改成true
[root@ff769b402f81 ~]# vi /etc/supervisord.conf
.......
15 [supervisord]
16 logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
17 logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
18 logfile_backups=10 ; (num of main logfile rotation backups;default 10)
19 loglevel=info ; (log level;default info; others: debug,warn,trace)
20 pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
21 nodaemon=true ; (start in foreground if true;default false)
3.编辑dockerfile文件
[root@docker01 centos-ssh]# vim Dockerfile # Base Images FROM centos # Maintainer MAINTAINER xiao@qq.com # Run RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm RUN yum install wget sudo git tree net-tools openssh-clients openssh-server openssl-devel supervisor -y && yum clean all RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key RUN ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key # Set root passwd RUN echo "root:123.com" | chpasswd #For Supervisor ADD supervisord.conf /etc/supervisord.conf ADD sshd.ini /etc/supervisord.d/sshd.ini #Outside port EXPOSE 22 CMD ["/usr/bin/supervisord","-c","/etc/supervisord.conf"]
4.编写sshd.ini启动文件
[root@docker01 centos-ssh]# vim sshd.ini [program:sshd] command=/usr/sbin/sshd -D process_name=%(program_name)s autostart=true
5.构建镜像
[root@docker01 centos-ssh]# docker build -t system/centos:v3 .
6.启动镜像
[root@docker01 centos-ssh]# docker run -d --name centos-supervisor -p 2222:22 system/centos:v3 64e8ebc3a7da2958b923235403e93e131d2c49f17cd87e8fc6d59c26726385c1
7.ssh到容器中
[root@docker01 centos-ssh]# ssh -p 2222 root@192.168.1.23 The authenticity of host '[192.168.1.23]:2222 ([192.168.1.23]:2222)' can't be established. ECDSA key fingerprint is bb:e1:67:bc:00:85:9a:20:2e:3d:b6:88:9b:54:23:13. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[192.168.1.23]:2222' (ECDSA) to the list of known hosts. root@192.168.1.23's password: [root@64e8ebc3a7da ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.7 115664 14800 ? Ss 08:13 0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf root 7 0.0 0.2 112816 4272 ? S 08:13 0:00 /usr/sbin/sshd -D root 8 1.0 0.3 155236 6016 ? Ss 08:14 0:00 sshd: root@pts/0 root 10 0.3 0.1 15256 1996 pts/0 Ss 08:14 0:00 -bash root 23 0.0 0.0 55144 1844 pts/0 R+ 08:14 0:00 ps aux [root@64e8ebc3a7da ~]# supervisorctl status sshd RUNNING pid 7, uptime 0:02:22

浙公网安备 33010602011771号