6

so I have this nice rest API implemented in Flask running in docker and I am thinking about scaling. This is how I progressed:

CMD ["flask", "run", "--host=0.0.0.0"]

and

docker run -d -p 5000:5000 pyrest-alpine

works fine

CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "pyrest:app"]

and

docker run -d -p 5000:5000 pyrest-alpine

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

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-alpine

My question is Do I still use gunicorn when using docker swarm replication?

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.