Is supervisord needed for docker+gunicorn+nginx?

2019-06-19 02:42发布

问题:

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?

回答1:

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 ...).



回答2:

The simple answer is no. And yes you can start both nginx and gunicorn in the same container. You can either create a script which executes everything your container needs to run and start it with CMD at the end of your Dockerfile. Or you can combine everything like so:

CMD (cd /usr/src/app && \
     nginx && \
     gunicorn wsgi:application --config ../configs/gunicorn.conf)

Hope that helps!