Get the App
SLTechnology News&Howtos  ›  Servers  › 

Detailed explanation of Docker container running multiple commands (supervisor)

Shulou Source: shulou.com Published: 2022-06-02 03:03:20 09月25日 Update

First, brief introduction

Dockerfile runs with only one command, and when you want to run multiple commands in Docker, it is more appropriate to use supervisor to manage it.

Supervisor is a client/server system developed by Python that can manage and monitor processes on a UNIX-like operating system. It can start and shut down multiple processes at the same time, which is very convenient to use.

component

Supervisor consists of two main parts:

Supervisord (server part): mainly responsible for managing child processes, responding to client commands and log output, etc.

Supervisorctl (client part): command line client through which users can contact different supervisord processes, obtain the status of child processes, and so on.

Second, the problem is that the log is not output.

However, logs running with supervisor,Django will not be output in Docker. The default output is as follows:

2018-03-28 06 CRIT Supervisor running as root 48 20292 (no user in config file)

2018-03-28 06 INFO supervisord started with pid 48 purl 20308 1

2018-03-28 06 INFO spawned: 'celery_beat' with pid 7

2018-03-28 06 48 INFO spawned 21312: 'celery_worker' with pid 8

2018-03-28 06 48 21313 INFO spawned: 'django' with pid 9

2018-03-28 06 process has stayed up for 48 INFO success 22315 INFO success: celery_beat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

2018-03-28 06 process has stayed up for 48 INFO success 22315 INFO success: celery_worker entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

2018-03-28 06 process has stayed up for 48 INFO success 22315 INFO success: django entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

The supervisor configuration in the above Docker is as follows:

[supervisord] nodaemon=true [program:django] command=python manage.py runserver 0.0.0.0 program:django 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 configuration runs Django,celery simultaneously in the container.

Third, the solution

1. The improved configuration scheme

[inet_http_server] port=9001username=abcpassword=123456 [supervisord] nodaemon=truelogfile=/var/log/supervisor/supervisord.log; (main logfile; 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.logloglevel=inforedirect_stderr=true [program:celery_worker] command=python manage.py celery worker-c 4-l infologlevel=inforedirect_stderr=true [program:celery_beat] command=python manage.py celery beatloglevel=inforedirect_stderr=true

It is found that the log output of Django is written to the stderr.log file, so redirect the error log to the standard log in the configuration file.

Redirect_stderr=true

The generated log file in the container is as follows:

Root@a16bc77e96bc:/var/log/supervisor# lscelery_beat-stderr---supervisor-rSPQ7E.log django-stderr---supervisor-9LS_KA.logcelery_beat-stdout---supervisor-t5Q4UI.log django-stdout---supervisor-cTSBmq.logcelery_worker-stderr---supervisor-TRFzc7.log supervisord.logcelery_worker-stdout---supervisor-xNgeBU.log

2. View the log

When running the container, map out port 9001 and access it through ip:9001:

Click Tail-f to view the logs of each process.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Tags: Log process run output command part configuration container file management at the same time client client scheme system facet support multiple different appropriate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Apple Linux Redmi