本文介绍构建Supervisor Docker镜像,在Docker容器内管理配置Supervisor。
Dockerfile:
FROM centos:7
MAINTAINER phonecom<18819470615@163.com>
# supervisor配置文件路径
ENV SUPERVISORD_CONF=/etc/supervisord.conf
# supervisor临时文件路径(日志文件、sock文件、pid文件)
ENV SUPERVISORD_TMP_CONF=/tmp/supervisor
# supervisor程序块文件路径,即是[program]块
ENV SUPERVISORD_INCLUDE_FILE=/etc/supervisordfile
# web管理界面的IP
ENV SUPERVISORD_WEB_IP=*
# web管理界面的PORT
ENV SUPERVISORD_WEB_PORT=9001
# web管理界面的账号
ENV SUPERVISORD_WEB_ACCOUNT=admin
# web管理界面的密码
ENV SUPERVISORD_WEB_PASSWORD=adminpass
RUN mkdir -p ${SUPERVISORD_TMP_CONF}
RUN mkdir -p ${SUPERVISORD_INCLUDE_FILE}
RUN yum -y update
RUN yum install -y python-setuptools wget telinit openssh openssh-server
RUN wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O |python
RUN easy_install supervisor
RUN echo -e "[unix_http_server]\nfile=${SUPERVISORD_TMP_CONF}/supervisor.sock\n[inet_http_server]\nport=${SUPERVISORD_WEB_IP}:${SUPERVISORD_WEB_PORT}\nusername=${SUPERVISORD_WEB_ACCOUNT}\npassword=${SUPERVISORD_WEB_PASSWORD}\n[supervisord]\nlogfile=${SUPERVISORD_TMP_CONF}/supervisord.log\nlogfile_maxbytes=50MB\nlogfile_backups=10\nloglevel=info\npidfile=${SUPERVISORD_TMP_CONF}/supervisord.pid\nnodaemon=false\nminfds=1024\nminprocs=200\n[supervisorctl]\nserverurl=unix://${SUPERVISORD_TMP_CONF}/supervisor.sock\n[program:sshd]\ncommand=/usr/sbin/sshd -D\n[include]\nfiles = ${SUPERVISORD_INCLUDE_FILE}/*.ini" > ${SUPERVISORD_CONF}
USER root
EXPOSE 22 80 9001
RUN /usr/sbin/init &
RUN /usr/sbin/telinit &
RUN sshd-keygen -t rsa -N "" -f ~/.ssh/id_rsa &
RUN sshd-keygen
CMD ["sh", "-c", "supervisord -c /etc/supervisord.conf && tail -f /dev/null"]
构建镜像:
docker build -t super .
启动容器:
docker run -d -p 9001:9001 super
访问 http://your-host:9001,输入用户名密码(admin/adminpass)
![](https://img.haomeiwen.com/i18097588/1ec57d1620eb92db.png)
cat /etc/supervisord.conf
[unix_http_server]
file=/tmp/supervisor/supervisor.sock
[inet_http_server]
port=*:9001
username=admin
password=adminpass
[supervisord]
logfile=/tmp/supervisor/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/tmp/supervisor/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
[supervisorctl]
serverurl=unix:///tmp/supervisor/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[include]
files = /etc/supervisordfile/*.ini
[program:sshd]
command=/usr/sbin/sshd -D
网友评论