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?
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.
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.
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/
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.
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 ...
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With