Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is supervisord needed for docker+gunicorn+nginx?

I'm running django with gunicorn inside docker, my entry point for docker is:

CMD ["gunicorn", "myapp.wsgi"]

Assuming there is already a process that run the docker when the system starts and restart the docker container when it stops, do I even need to use supervisord? if gunicorn will crash won't it crash the docker and then restart?

like image 513
Dan Bolofe Avatar asked Aug 02 '16 13:08

Dan Bolofe


People also ask

Should I use Supervisord in docker?

Yes, although it depends on how your main process runs (foreground or background), and how it collects child processes. docker stop stops a running container by sending it SIGTERM signal, let the main process process it, and after a grace period uses SIGKILL to terminate the application.

Does Gunicorn need nginx?

It is recommended in Gunicorn docs to run it behind a proxy server. Technically, you don't really need Nginx. BUT it's the Internet: your server will receive plenty of malformed HTTP requests which are made by bots and vulnerability scanner scripts.

What is Supervisord in docker?

Supervisor daemon is used to start and supervise more than one process in Docker containers. More about supervisor can be found on supervisor homepage at http://supervisord.org/

What is Gunicorn docker?

Gunicorn is a common WSGI server for Python applications, but most Docker images that use it are badly configured. Running in a container isn't the same as running on a virtual machine or physical server, and there are also Linux-environment differences to take into account.


1 Answers

The only time you need something like supervisord (or other process supervisor) in a Docker container is if you need to start up multiple independent processes inside the container when the it starts.

For example, if you needed to start both nginx and gunicorn in the same container, you would need to investigate some sort of process supervisor. However, a much more common solution would be to place these two services in two separate containers. A tool like docker-compose helps manage multi-container applications.

If a container exits because the main process exits, Docker will restart that container if you configured a restart policy when you first started it (e.g., via docker run --restart=always ...).

like image 129
larsks Avatar answered Sep 23 '22 05:09

larsks