You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🚨 These tags are no longer supported or maintained, they are removed from the GitHub repository, but the last versions pushed might still be available in Docker Hub if anyone has been pulling them:
15
13
14
+
*`python3.8`
16
15
*`python3.8-alpine`
16
+
*`python3.7`
17
17
*`python3.6`
18
18
*`python2.7`
19
19
20
20
The last date tags for these versions are:
21
21
22
+
*`python3.8-2024-10-28`
22
23
*`python3.8-alpine-2024-03-11`
24
+
*`python3.7-2024-10-28`
23
25
*`python3.6-2022-11-25`
24
26
*`python2.7-2022-11-25`
25
27
@@ -35,30 +37,11 @@ The last date tags for these versions are:
35
37
36
38
This [**Docker**](https://www.docker.com/) image allows you to create [**Flask**](http://flask.pocoo.org/) web applications in [**Python**](https://www.python.org/) that run with [**uWSGI**](https://uwsgi-docs.readthedocs.org/en/latest/) and [**Nginx**](http://nginx.org/en/) in a single container.
37
39
38
-
The combination of uWSGI with Nginx is a [common way to deploy Python Flask web applications](http://flask.pocoo.org/docs/1.0/deploying/uwsgi/). It is widely used in the industry and would give you decent performance. (*)
39
-
40
-
There is also an Alpine version. If you want it, check the tags from above.
41
-
42
-
### * Note on performance and features
43
-
44
-
If you are starting a new project, you might benefit from a newer and faster framework based on ASGI instead of WSGI (Flask and Django are WSGI-based).
45
-
46
-
You could use an ASGI framework like:
47
-
48
-
*[**FastAPI**](https://github.com/tiangolo/fastapi) (which is based on Starlette) with this Docker image: [**tiangolo/uvicorn-gunicorn-fastapi**](https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker).
49
-
*[**Starlette**](https://github.com/encode/starlette) directly, with this Docker image: [**tiangolo/uvicorn-gunicorn-starlette**](https://github.com/tiangolo/uvicorn-gunicorn-starlette-docker).
50
-
51
-
FastAPI, or Starlette, would give you about 800% (8x) the performance achievable with Flask using this image (**tiangolo/uwsgi-nginx-flask**). [You can see the third-party benchmarks here](https://www.techempower.com/benchmarks/#section=test&runid=a979de55-980d-4721-a46f-77298b3f3923&hw=ph&test=fortune&l=zijzen-7).
52
-
53
-
Also, if you want to use new technologies like WebSockets it would be easier (and *possible*) with a newer framework based on ASGI, like FastAPI or Starlette. As the standard ASGI was designed to be able to handle asynchronous code like the one needed for WebSockets.
54
-
55
-
#### If you need Flask
56
-
57
-
If you need to use Flask (instead of something based on ASGI) and you need to have the best performance possible, you can use the alternative image: [**tiangolo/meinheld-gunicorn-flask**](https://github.com/tiangolo/meinheld-gunicorn-flask-docker).
40
+
The combination of uWSGI with Nginx is a [common way to deploy Python Flask web applications](http://flask.pocoo.org/docs/1.0/deploying/uwsgi/).
58
41
59
-
**tiangolo/meinheld-gunicorn-flask** will give you about 400% (4x) the performance of this image (**tiangolo/uwsgi-nginx-flask**).
42
+
### Alternative - FastAPI
60
43
61
-
It is very similar to **tiangolo/uwsgi-nginx-flask**, so you can still use many of the ideas described here.
44
+
If you are starting a new project, you might want to try [**FastAPI**](https://github.com/tiangolo/fastapi), which I created, and where I spend most of my time now. It also doesn't need a custom base image, there are instructions in the docs to build your own `Dockerfile`.
62
45
63
46
---
64
47
@@ -93,7 +76,7 @@ threads = 3
93
76
And then you could have a `Dockerfile` with:
94
77
95
78
```Dockerfile
96
-
FROM python:3.9
79
+
FROM python:3.12
97
80
98
81
WORKDIR /code
99
82
@@ -120,7 +103,7 @@ You could be deploying to a **single server** (not a cluster) with **Docker Comp
120
103
121
104
Then you could want to have **a single container** with a **process manager** starting **several worker processes** inside, as this Docker image does.
122
105
123
-
### Prometheus and Other Reasons
106
+
### Other Reasons
124
107
125
108
You could also have **other reasons** that would make it easier to have a **single container** with **multiple processes** instead of having **multiple containers** with **a single process** in each of them.
126
109
@@ -134,20 +117,6 @@ Then, in that case, it could be simpler to have **one container** with **multipl
134
117
135
118
Read more about it all in the [FastAPI documentation about: FastAPI in Containers - Docker](https://fastapi.tiangolo.com/deployment/docker/), as the same concepts apply to other web applications in containers.
136
119
137
-
## Examples (simple project templates)
138
-
139
-
***`python3.8`** tag: general Flask web application:
***`python3.8`** tag: general Flask web application, structured as a package, for bigger Flask projects, with different submodules. Use it only as an example of how to import your modules and how to structure your own project:
***`python3.8`** tag: `static/index.html` served directly in `/`, e.g. for [Vue](https://vuejs.org/), [React](https://reactjs.org/), [Angular](https://angular.io/), or any other Single-Page Application that uses a static `index.html`, not modified by Python:
There are several image tags available but for new projects you should use the latest version available.
170
139
171
-
There are several template projects that you can download (as a `.zip` file) to bootstrap your project in the section "**Examples (project templates)**" above.
172
-
173
140
This Docker image is based on [**tiangolo/uwsgi-nginx**](https://hub.docker.com/r/tiangolo/uwsgi-nginx/). That Docker image has uWSGI and Nginx installed in the same container and was made to be the base of this image.
174
141
175
142
## Quick Start
176
143
177
-
**Note**: You can download the **example-flask-python3.8.zip** project example and use it as the template for your project from the section **Examples** above.
178
-
179
-
---
180
-
181
-
Or you may follow the instructions to build your project from scratch:
You should be able to check it in your Docker container's URL, for example: <ahref="http://192.168.99.100"target="_blank">http://192.168.99.100</a> or <ahref="http://127.0.0.1"target="_blank">http://127.0.0.1</a>
237
198
238
-
## Project Generators
239
-
240
-
There are several project generators that you can use to start your project, with everything already configured.
241
-
242
-
### Server set up
243
-
244
-
All these project generators include automatic and free HTTPS certificates generation provided by:
245
-
246
-
*[Traefik](https://traefik.io/) and
247
-
*[Let's Encrypt](https://letsencrypt.org/)
248
-
249
-
...using the ideas from [DockerSwarm.rocks](https://dockerswarm.rocks).
250
-
251
-
It would take about 20 minutes to read that guide and have a Docker cluster (of one or more servers) up and running ready for your projects.
252
-
253
-
You can have several projects in the same cluster, all with automatic HTTPS, even if they have different domains or sub-domains.
254
-
255
-
### Generate a project
256
-
257
-
Then you can use one of the following project generators.
258
-
259
-
It would take about 5 extra minutes to generate one of these projects.
260
-
261
-
### Deploy
262
-
263
-
And it would take about 3 more minutes to deploy them in your cluster.
264
-
265
-
---
266
-
267
-
In total, about 28 minutes to start from scratch and get an HTTPS Docker cluster with your full application(s) ready.
Minimal project generator with a Flask backend, a modern frontend (Vue, React or Angular) using Docker multi-stage building and Nginx, a Traefik load balancer with HTTPS, Docker Compose (and Docker Swarm mode) etc.
Full stack project generator with Flask backend, CouchDB, Celery asynchronous jobs, API testing, CI integration, Docker Compose (and Docker Swarm mode), Swagger, automatic HTTPS, Vue.js, etc.
298
-
299
-
Similar to `full-stack-flask-couchbase`, but with CouchDB instead of Couchbase (or PostgreSQL).
300
-
301
199
## Quick Start for SPAs *
302
200
303
201
### Modern Single Page Applications
@@ -353,16 +251,8 @@ In this scenario, you would have 3 Docker containers:
353
251
* Frontend (Vue.js, Angular, React or any other)
354
252
* Traefik (load balancer, HTTPS)
355
253
356
-
### Deprecated Single Page Applications guide
357
-
358
-
If you want to check the previous (deprecated) documentation on adding a frontend to the same container, you can [read the deprecated guide for single page apps](https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/deprecated-single-page-apps-in-same-container.md).
359
-
360
254
## Quick Start for bigger projects structured as a Python package
361
255
362
-
**Note**: You can download the **example-flask-package-python3.8.zip** project example and use it as an example or template for your project from the section **Examples** above.
363
-
364
-
---
365
-
366
256
You should be able to follow the same instructions as in the "**QuickStart**" section above, with some minor modifications:
367
257
368
258
* Instead of putting your code in the `app/` directory, put it in a directory `app/app/`.
@@ -842,8 +732,6 @@ if __name__ == "__main__":
842
732
843
733
...and you could run it with `python main.py`. But that will only work when you are not using a package structure and don't plan to do it later. In that specific case, if you didn't add the code block above, your app would only listen to `localhost` (inside the container), in another port (5000) and not in debug mode.
844
734
845
-
**Note**: The example project **example-flask-python3.8** includes a `docker-compose.yml` and `docker-compose.override.yml` with all these configurations, if you are using Docker Compose.
846
-
847
735
---
848
736
849
737
Also, if you want to do the same live debugging using the environment variable `STATIC_INDEX=1` (to serve `/app/static/index.html` directly when requested for `/`) your Nginx won't serve it directly as it won't be running (only your Python Flask app in debug mode will be running).
@@ -884,8 +772,6 @@ def route_frontend(path):
884
772
885
773
That's how it is written in the tutorial above and is included in the downloadable examples.
886
774
887
-
**Note**: The example project **example-flask-python3.8-index** includes a `docker-compose.yml` and `docker-compose.override.yml` with all these configurations, if you are using Docker Compose.
888
-
889
775
## More advanced development instructions
890
776
891
777
If you follow the instructions above, it's probable that at some point, you will write code that will break your Flask debugging server and it will crash.
@@ -924,34 +810,10 @@ flask run --host=0.0.0.0 --port=80
924
810
925
811
You will see your Flask debugging server start, you will see how it sends responses to every request, you will see the errors thrown when you break your code, and how they stop your server, and you will be able to re-start it very fast, by just running the command above again.
926
812
927
-
## 🚨 Alpine Python Warning
928
-
929
-
In short: You probably shouldn't use Alpine for Python projects, instead use the `slim` Docker image versions.
930
-
931
-
---
932
-
933
-
Do you want more details? Continue reading 👇
934
-
935
-
Alpine is more useful for other languages where you build a static binary in one Docker image stage (using multi-stage Docker building) and then copy it to a simple Alpine image, and then just execute that binary. For example, using Go.
936
-
937
-
But for Python, as Alpine doesn't use the standard tooling used for building Python extensions, when installing packages, in many cases Python (`pip`) won't find a precompiled installable package (a "wheel") for Alpine. And after debugging lots of strange errors you will realize that you have to install a lot of extra tooling and build a lot of dependencies just to use some of these common Python packages. 😩
938
-
939
-
This means that, although the original Alpine image might have been small, you end up with a an image with a size comparable to the size you would have gotten if you had just used a standard Python image (based on Debian), or in some cases even larger. 🤯
940
-
941
-
And in all those cases, it will take much longer to build, consuming much more resources, building dependencies for longer, and also increasing its carbon footprint, as you are using more CPU time and energy for each build. 🌳
942
-
943
-
If you want slim Python images, you should instead try and use the `slim` versions that are still based on Debian, but are smaller. 🤓
944
-
945
813
## Tests
946
814
947
815
All the image tags, configurations, environment variables and application options are tested.
948
816
949
-
## Updates
950
-
951
-
Updates are announced in the releases.
952
-
953
-
You can click the "watch" button at the top right and select "Releases only" to receive an email notification when there's a new release.
0 commit comments