I\'m unable to shut down Docker containers that were launched by supervisor through supervisorctl stop all
. Even through supervisorctl status
shows the
I think I found the problem. I didn't realise it, but there's multiple ways of starting a program when a docker container is fired up.
Apparently CMD myexec param1 param2
starts a shell which in turn starts myexec
(in fact these two processes are visible in the container with /bin/sh -c myexec...
at PID 1. A better way is to start the program directly (in my case supervisord).
On the other hand, CMD ["/usr/bin/python", "/usr/local/bin/supervisord", "-c", "/root/supervisord.conf", "--nodaemon"]
worked fine. I am now able to start and stop the docker container through supervisor.
Here's the relevant section in the docker docs:
The CMD instruction has three forms:
CMD ["executable","param1","param2"]
(exec form, this is the preferred form)
CMD ["param1","param2"]
(as default parameters to ENTRYPOINT)
CMD command param1 param2
(shell form)
Update
Example supervisor file (inside Docker container):
[program:app]
command=python run_web_server.py
stdout_logfile=/var/log/app/app.log
directory=/opt/app
autostart=true
autorestart=false
stopsignal=INT
redirect_stderr=true
startretries=0
stopasgroup=true
killasgroup=true
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
The mako template to generate the Docker (outside) supervisor file:
[program:container]
command=docker run --rm --name ${name} \
% if container_links is not UNDEFINED:
% for host in container_hosts:
--add-host ${host['name']}:${host['ip']} \
% endfor
% endif
% if container_links is not UNDEFINED:
% for link in container_links:
--link ${link}:${link} \
% endfor
% endif
% if port_mappings is not UNDEFINED:
% for ext in port_mappings:
-p ${ext}:${port_mappings[ext]} \
% endfor
% endif
-e "INSTANCE_NAME=${name}" \
-e "TZ=${timezone}" \
% if environ is not UNDEFINED:
% for k in environ:
-e "${k}=${environ[k]}" \
% endfor
% endif
-v ${deployment_dir}/tmp:${deployment_dir}/app/tmp \
... more -v
-i foo/app-${version}:${type}
stdout_logfile=${deployment_dir}/log/${name}.log
redirect_stderr=true
autostart=false
autorestart=false
% if priority is not UNDEFINED:
priority=${priority}
% endif
startretries=0
# stopasgroup=true
# killasgroup=true