Docker is mostly used for packing the application, the goal is generally that anyone could execute
docker run <containername>
so how does docker know what to execute? It uses ENTRYPOINT or CMD to start services, Both parameters are used to specify the programs/commands to execute while initializing a container from the docker image.
The container's primary process is responsible for managing all operations that it starts which we define at ENTRYPOINT or CMD at the end of the Dockerfile. Docker always recommends that your areas of concern be by using one service per container.
Supervisor A process control system
A supervisor is a client/server system that allows its users to monitor and control many processes on UNIX-like operating systems.
It is meant to be used to control processes related to a project or a customer and to start like any other program at boot time.
I have detail explained about supervisord in this article.
Multiple services in a container
-
Dockerfile CMD
CMD ["supervisord", "-c", "/path/to_your_file/supervisor.conf", "-n"]
Supervisor conf file sample
[unix_http_server]
file=/tmp/supervisor.sock
chmod=0755
[supervisord]
logfile=/tmp/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
;environment variables
environment=ENV="PROD",
PATH="/path/../...",
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[program:redis-server]
command=redis-server
process_name=%(program_name)s
numprocs=1
directory=/home/path/to/location/
autostart=true
autorestart=true
startsecs=10
stopsignal=TERM
stopwaitsecs=5 ; max num secs to wait b4 SIGKILL (default 10)
user=root
priority=1
stopasgroup=true
killasgroup=true
[program:logger]
command=/home/path/to/excutable/logger
process_name=%(program_name)s
numprocs=1
directory=/home/path/to/location/
autostart=true
autorestart=true
startsecs=10
stopsignal=TERM
stopwaitsecs=5
user=root
priority=30
stopasgroup=true
killasgroup=true
In the above config file, we have two services one is Redis-server and logger services running as root. Each service has priority to start services. for each config param refer to the supervised documentation
In the command section, You can also use a shell script to run your services but be aware of the zombie process created when you kill or restart the services.
Oldest comments (0)