I. Introduction
Dockerfile run only support a single command, when you want to run more than one command at Docker years, with a supervisor to manage it more appropriate.
Supervisor is a Python developer of client / server system that can manage and monitor above the operating system UNIX-like process. It can be started at the same time, turn off multiple processes, particularly convenient to use.
component
supervisor mainly consists of two parts:
- supervisord (server part): responsible for managing the child, responder command and the log output and other customers;
- supervisorctl (client part): command-line client, users can contact it with a different supervisord process, the state acquiring sub-process and so on.
Second, there is the problem - not the log output
But using supervisor, log Django will not run in the output of the Docker, the default output is as follows:
2018-03-28 06:48:20,292 CRIT Supervisor running as root (no user in config file)
2018-03-28 06:48:20,308 INFO supervisord started with pid 1
2018-03-28 06:48:21,310 INFO spawned: 'celery_beat' with pid 7
2018-03-28 06:48:21,312 INFO spawned: 'celery_worker' with pid 8
2018-03-28 06:48:21,313 INFO spawned: 'django' with pid 9
2018-03-28 06:48:22,315 INFO success: celery_beat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-03-28 06:48:22,315 INFO success: celery_worker entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-03-28 06:48:22,315 INFO success: django entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
Docker supervisor in the above configuration is as follows:
[supervisord]
nodaemon=true
[program:django]
command=python manage.py runserver 0.0.0.0:8080
[program:celery_worker]
command=python manage.py celery worker -c 4 -l info
[program:celery_beat]
command=python manage.py celery beat
Such a container is disposed in the run Django, celery.
Third, the solution
1, the improved configuration scheme
[inet_http_server]
port=9001
username=abc
password=123456
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
[program:django]
command=python manage.py runserver 0.0.0.0:8080
#stdout_logfile = /var/log/supervisord/django_stdout.log
loglevel=info
redirect_stderr=true
[program:celery_worker]
command=python manage.py celery worker -c 4 -l info
loglevel=info
redirect_stderr=true
[program:celery_beat]
command=python manage.py celery beat
loglevel=info
redirect_stderr=true
Django will find actual log output is written to stderr.log file, so in the configuration file to redirect standard error log log;
redirect_stderr=true
Container log files generated as follows:
root@a16bc77e96bc:/var/log/supervisor# ls
celery_beat-stderr---supervisor-rSPQ7E.log django-stderr---supervisor-9LS_KA.log
celery_beat-stdout---supervisor-t5Q4UI.log django-stdout---supervisor-cTSBmq.log
celery_worker-stderr---supervisor-TRFzc7.log supervisord.log
celery_worker-stdout---supervisor-xNgeBU.log
2, View Log
When you run the vessel, port 9001 is mapped out by ip: 9001 Access:
[Image upload failed ... (image-20da97-1522375135673)]
Click Tail -f to see the log of each process.
reference
On the blog: http://kekefund.com/2018/03/30/supervisor/