patterndockerMinor
Flask, Gunicorn and Docker Swarm
Viewed 0 times
swarmflaskgunicorndockerand
Problem
so I have this nice rest API implemented in Flask running in docker and I am thinking about scaling. This is how I progressed:
and
works fine
and
This also works fine, Gunicorn provided some scaling via prefork worker model in a single container now I want to scale via replication of Docker swarm with healthchecks where both
and
work just fine with
My question is Do I still use gunicorn when using docker swarm replication?
CMD ["flask", "run", "--host=0.0.0.0"]and
docker run -d -p 5000:5000 pyrest-alpineworks fine
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "pyrest:app"]and
docker run -d -p 5000:5000 pyrest-alpineThis also works fine, Gunicorn provided some scaling via prefork worker model in a single container now I want to scale via replication of Docker swarm with healthchecks where both
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "pyrest:app"]and
CMD ["flask", "run", "--host=0.0.0.0"]work just fine with
docker service create --name pyrest-swarm --replicas 2 -p 5000:5000 --health-interval=2s --health-timeout=10s --health-retries=3--health-cmd "curl 0.0.0.0:5000/status || exit 1" pyrest-alpineMy question is Do I still use gunicorn when using docker swarm replication?
Solution
Yes, when using Docker Swarm you'll still want to use Gunicorn in your Docker containers.
Gunicorn is necessary to facilitate the communication between the server and your web application. In the case of a Dockerized Flask application this is still the case as Gunicorn handles the communication between the Flask application and the Docker container. Adding Docker Swarm to this stack basically just means that you have more instances of your container, and that Swarm will handle balancing the incoming requests to each instance.
Gunicorn is necessary to facilitate the communication between the server and your web application. In the case of a Dockerized Flask application this is still the case as Gunicorn handles the communication between the Flask application and the Docker container. Adding Docker Swarm to this stack basically just means that you have more instances of your container, and that Swarm will handle balancing the incoming requests to each instance.
Context
StackExchange DevOps Q#2619, answer score: 2
Revisions (0)
No revisions yet.