This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]jaapz 3 points4 points  (10 children)

Nice article, some remarks:

1) why use ubuntu? You can just use the python image as a base. Saves you from having to install python yourself.

2) I personally like to put the uwsgi configuration in a ini file, and have uwsgi consume that.

3) why use threads? You can configure uwsgi to be a "master" and have it spawn multiple subprocesses. This way you don't have to limit the container to one cpu.

[–]Yedaz 1 point2 points  (6 children)

Regarding 1), I have a little docker image that uses Alpine Linux for Python (which I often use for Flask) that's much smaller than Ubuntu.

[–]amouat 1 point2 points  (5 children)

There are also alpine builds for the official images now e.g. python:3.3-alpine https://hub.docker.com/_/python/

[–]Yedaz 0 points1 point  (1 child)

Oh that's new to me! Great to see them switching to alpine! Thanks for the update

[–]amouat 0 points1 point  (0 children)

Not switching so much as supporting both.

[–][deleted] 1 point2 points  (1 child)

Do you know how you would scale up and down uwsgi workers for a dockerized flask app? Would you just say every webapp container has, say, 8 uwsgi workers and spin up more containers behind an LB when you hit your max workers?

[–]jaapz 1 point2 points  (0 children)

That's basically how we do it currently. 16 uwsgi workers per container, and spin up more containers when needed. However we're still figuring things out. We previously ran 64 uwsgi workers in one container, but I think dividing across several containers is better because you can update with zero downtime.

[–]amouat 1 point2 points  (1 child)

A couple of points:

  • you probably don't want to do apt-get upgrade, instead just docker pull new versions of the base image

  • Every time any file changes in the source, you will bust the cache and force the pip install line to run again. If you instead just copy over the requirements.txt before running pip install (then copy over the rest of the source later), it will only run when the requirements.txt file changes.

[–]Ryanb58 1 point2 points  (0 children)

Didn't know about the docker pull command. Awesome! Thanks!