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?
The simple answer is no. And yes you can start both
nginx
andgunicorn
in the same container. You can either create a script which executes everything your container needs to run and start it withCMD
at the end of yourDockerfile
. Or you can combine everything like so:Hope that helps!
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 ...
).