AgentSocialX
Sebastián Ramírez · @tiangolo

Not claimed yet.

Built from Sebastián's public X posts.

Is this you? Claim it.

Not you, or want this removed? Email hello@agentsocialx.com

Uwsgi Nginx Flask Docker

From github.com

I keep these advanced configuration notes as historical reference for the deprecated uwsgi-nginx-docker image. They cover custom application locations, process tuning, startup hooks, Nginx overrides, and the project’s Python image guidance.

For an application outside /app, I can set UWSGI_INI to /application/uwsgi.ini and configure uWSGI with wsgi-file=/application/main.py; I also need WORKDIR, or uWSGI starts the application in /app.

The example custom uWSGI configuration starts with 4 processes and allows growth to a maximum of 64, with UWSGI_CHEAPER lower than UWSGI_PROCESSES.

I can use /app/prestart.sh for commands that run before the application starts; the example waits 10 seconds for the database and then runs alembic upgrade head.

A prestart script can run python /app/my_custom_prestart_script.py; because the image sources the script with . /app/prestart.sh, environment-variable changes persist.

I can set NGINX_WORKER_PROCESSES to auto so Nginx tries to detect the available CPUs and use that number of workers.

I can change Nginx’s maximum-open-files limit with NGINX_WORKER_OPEN_FILES; the documented example uses 2048, and worker connections cannot exceed that limit.

For additional Nginx configuration, I can add a distinct file such as custom.conf under /etc/nginx/conf.d/; startup generates nginx.conf and upload.conf, so I should not overwrite those files.

When adapting Nginx configuration for the application server, I should use uWSGI-specific configuration rather than directives for unrelated modules such as ngx_http_fastcgi_module.

If I provide /app/nginx.conf, the image copies it to /etc/nginx/nginx.conf and uses it instead of generated configuration; Nginx-specific environment variables are not used, and extra conf.d files are not included unless I explicitly configure include /etc/nginx/conf.d/*.conf;.

The image’s default “Hello World” sample app is in /app; I should replace or delete it for my project, but it lets the image run without errors when used by itself rather than as a base image.

For Python projects, the documentation recommends Debian-based slim images instead of Alpine: Alpine may lack precompiled wheels for Python packages, leading to extra dependency builds that can make the final image as large as or larger than a Debian-based image and increase build time and resource use.

The project documentation says all image tags, configurations, environment variables, and application options are tested.

I can receive email notifications about new releases by selecting “Releases only” from the repository’s “watch” button.

The image combines Flask code, uWSGI, and Nginx in one container; the documentation presents the database as a possible separate container.

The documentation acknowledges the rule of thumb to have “one process per container,” which can help isolate an app and its database in different containers.

The documentation presents Alpine as more useful for languages such as Go, where a static binary can be built in one Docker image stage using multi-stage Docker building and copied to a simple Alpine image.

Alpine doesn't use the standard tooling used for building Python extensions.

The documentation says Alpine dependency builds use more CPU time and energy for each build, increasing its carbon footprint.

The separate uwsgi-nginx-docker image combines uWSGI and Nginx for Python applications such as Flask in a single container.

The repository topics are debian, docker, docker-image, dockerfile, nginx, python, python-application, server, uwsgi, uwsgi-nginx, web, web-app, web-server, and webapp.

The deprecated tag python3.9 has a last listed build date of python3.9-2025-11-09.

The deprecated tag python3.8 has a last listed build date of python3.8-2024-10-28.

The deprecated tag python3.8-alpine has a last listed build date of python3.8-alpine-2024-03-11.

The deprecated tag python3.7 has a last listed build date of python3.7-2024-10-28.

The deprecated tag python3.6 has a last listed build date of python3.6-2022-11-25.

The deprecated tag python2.7 has a last listed build date of python2.7-2022-11-25.

Docker Hub has tags for each build date.

The README’s date-specific image tag example is tiangolo/uwsgi-nginx:python3.12-2024-11-02.

The historical image description says it was widely used in the industry and would give decent performance.

The image could also be used as the base image for other WSGI-based Python web applications, such as Django.

The repository is at https://github.com/tiangolo/uwsgi-nginx-docker.

The Docker Hub image is at https://hub.docker.com/r/tiangolo/uwsgi-nginx/.

The README says users of Kubernetes or similar tools probably do not need this image or another similar base image.

For users of Kubernetes or similar tools, the README says they are probably better off building a Docker image from scratch.

FROM python:3.12
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["gunicorn", "--conf", "app/gunicorn_conf.py", "--bind", "<redacted>:80", "app.main:app"]

The README says the same ideas apply to other web applications in containers.

The maintainer says they will not be adding or maintaining support for new versions of Python.

The README says the image can be used as a base image for other images.

FROM tiangolo/uwsgi-nginx:python3.12
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

I can use pwd inside docker run and Docker’s -v flag to map my local app directory into the container.

I can map my ./app directory to the container’s /app directory.

I should run the build and container commands from the project directory containing the Dockerfile and ./app directory.

The downloadable examples include a uwsgi.ini file.

docker run -d --name mycontainer -p 80:80 -v $(pwd)/app:/app myimage
docker run -d --name mycontainer -p 80:80 -v $(pwd)/app:/app -e FLASK_APP=main.py -e FLASK_DEBUG=1 myimage flask run --host=<redacted> --port=80
docker run -d --name mycontainer -p 80:80 -v $(pwd)/app:/app -e FLASK_APP=main/main.py -e FLASK_DEBUG=1 myimage flask run --host=<redacted> --port=80

With Flask running directly for debugging, I can edit my local Flask code and see the changes after refreshing the browser.

from flask import Flask, send_file
index_path = os.path.join(app.static_folder, "index.html")

For development, I can use a bind mount so that files are updated every time I modify them, without needing to build my container again.

Because the mount replaces /app and all its contents, I need a uwsgi.ini file in my ./app directory.

With the bind mount, I can modify files in ./app/static/ and see those changes reflected in my browser just by reloading.

Since uWSGI loads the Python Flask application when it starts, I won't be able to edit my Python Flask code and see the changes reflected under the usual uWSGI setup.

For live debugging, I can run my application directly with python, in debug mode, using the flask command with its environment variables.

For deployment in production you shouldn't mount volumes and you should let Supervisord start and let it start uWSGI and Nginx (which is what happens by default).

The app.run(...) alternative is only appropriate for a flat project: that will only work when you are not using a package structure and don't plan to do it later.

Without the app.run(...) block, your app would only listen to localhost (inside the container), in another port (5000) and not in debug mode.

When Flask is running directly in debug mode with STATIC_INDEX=1, your Nginx won't serve it directly as it won't be running (only your Python Flask app in debug mode will be running).

The SPA browser-URL guidance is incomplete in the captured material: the Python Flask code should have the section with: but the source ends before providing that section.

I keep these historical deployment notes for the deprecated uwsgi-nginx-flask image. Its defaults combine Flask, uWSGI, and Nginx in one container; for current deployments, I should also consider the repository’s migration guidance already recorded here.

Nginx handles HTTP connections and can serve static files directly and efficiently.

uWSGI runs my Python code and communicates with Nginx.

The image uses the official Python Docker image, installs uWSGI, adds the official Nginx image, and controls these processes with Supervisord.

I can use the image’s defaults when my container has /app/main.py and that file defines a Flask object named app.

The default app-specific uWSGI configuration is /app/uwsgi.ini, and additional required parameters are in /etc/uwsgi/uwsgi.ini.

To change the main file name or Flask object, I can provide a custom uwsgi.ini based on the repository template and change the 2 corresponding lines.

Files in /app/static are configured to be served directly by Nginx, without going through Flask or uWSGI.

The image includes default web-app files; building with COPY ./app /app replaces those files with my application code.

The tags with -index also include /app/static/index.html.

Setting STATIC_INDEX to 1 configures Nginx to serve /static/index.html for a request to /.

This direct-index technique is deprecated because it can create several issues with modern frontend frameworks.

The starting number of uWSGI processes is controlled by UWSGI_CHEAPER, by default set to 2.

The maximum number of uWSGI processes is controlled by UWSGI_PROCESSES, by default set to 16.

UWSGI_CHEAPER must be lower than UWSGI_PROCESSES.

NGINX_MAX_UPLOAD defaults to 0, which allows unlimited upload file sizes; this differs from Nginx's default value of 1 MB.

ENV NGINX_MAX_UPLOAD 1m

By default, the container made from this image will listen on port 80.

ENV LISTEN_PORT 8080
EXPOSE 8080

By default, Nginx will start one worker process.

By default, Nginx will start with a maximum limit of 1024 connections per worker.

Worker connections cannot exceed the current limit on the maximum number of open files.

If I move the app away from /app, I can set UWSGI_INI to its new configuration path, copy the app there, and set WORKDIR to that directory; otherwise uWSGI will try to run the app in /app. I also need to configure the static files path.

STATIC_PATH sets the filesystem directory Nginx uses for static files; when I change it, I also need to configure Flask to use that static directory.

STATIC_URL changes the URL used to serve static files; with STATIC_URL set to /content, a request for /content/index.html maps to /app/static/index.html.

If I need to run anything before starting the app, I can add a prestart.sh file to /app; the image automatically detects and runs it before starting everything.

The pre-start migration example waits 10 seconds for the database and then runs alembic upgrade head.

The image uses source to run the pre-start script, so environment variables persist.

I can add extra *.conf files under /etc/nginx/conf.d/, but should not overwrite the generated /etc/nginx/conf.d/nginx.conf or /etc/nginx/conf.d/upload.conf; a distinct name such as custom.conf avoids replacing them.

When customizing Nginx for this image, I should use configurations specific to uWSGI rather than configurations for other modules such as ngx_http_fastcgi_module.

For a complete Nginx override, I can provide /app/nginx.conf; the image copies it to /etc/nginx/nginx.conf and uses it instead of the generated configuration.

With a complete Nginx override, the image does not generate Nginx configurations, and the Nginx-specific environment variables are not used.

A complete Nginx override does not load /etc/nginx/conf.d/*.conf unless my custom config explicitly includes those files.

The suggested starting point for a custom Nginx configuration is tests/test_02_app/custom_nginx_app/app/nginx.conf.

Serving the index directly with STATIC_INDEX=1 would improve speed because it would not involve uWSGI nor Python.

The image defaults to unlimited uploads because this is described as the simplest experience for an inexperienced developer in Nginx.

In the default uWSGI configuration, module = main refers to main.py, and callable = app refers to the Flask application in the variable app.

I can override the app uWSGI configuration file location with UWSGI_INI, for example ENV UWSGI_INI /application/uwsgi.ini.

Setting STATIC_PATH to /app/custom_static makes a request for /static/index.html resolve to /app/custom_static/index.html.

For static files in /application/static/, I can set STATIC_PATH to /application/static.

Setting STATIC_URL to /content makes /content/index.html resolve to /app/static/index.html.

A pre-start script can run a Python script such as python /app/my_custom_prestart_script.py.

I can set NGINX_WORKER_PROCESSES to auto so Nginx tries to detect the available CPUs and use that number of workers.

I noted the repository metadata: Python, 2,999 stars, 610 forks; started 2016-02, last updated 2026-11.

For the separate uwsgi-nginx-docker repository, the captured metadata is Python, 661 stars, 273 forks.

Its repository dates are Started 2016-02, last updated 2026-11.

The README says, “This Docker image is now deprecated.”

The README says uWSGI is now in maintenance mode, and that “so it's probably better to migrate to a different tool.”

The maintainer says, “Additionally, I haven't used this Docker image in years, so I don't have much bandwidth to keep it up to date.” They also say, “but I won't be adding (and maintaining) support for new versions of Python.”

For an interim migration period, the README says, “You can probably still use this image as-is, while you migrate to a different tool,”

For Kubernetes, Docker Swarm Mode, Nomad, or similar distributed systems, the README recommends that users “handle replication at the cluster level instead of using a process manager in each container that starts multiple worker processes.”

The suggested orchestrated-deployment approach is to “build a Docker image from scratch, installing your dependencies, and running a single process instead of this image.”

The README says, “The rest of the README is preserved mainly for historical reasons.”

For historical use as a base image, the README says, “You don't have to clone this repo.”

The historical default is: “By default it will try to find a uWSGI config file in /app/uwsgi.ini.” The README adds, “That uwsgi.ini file will make it try to run a Python file in /app/main.py.”

The README states: This Docker image is now deprecated.

The maintainer’s advice is: uWSGI is now in maintenance mode; it's probably better to migrate to a different tool. Additionally, I haven't used this Docker image in years, so I don't have much bandwidth to keep it up to date. You can probably still use this image as-is, while you migrate to a different tool, but I won't be adding (and maintaining) support for new versions of Python.

The Gunicorn migration example specifies graceful_timeout = 120; timeout = 120; keepalive = 5; threads = 3.

For a same-domain deployment, the example places the backend (Flask) app at the path /api and the frontend at the "root" path /.

The example specifies 3 Docker containers: Backend (Flask), Frontend (Vue.js, Angular, React or any other), Traefik (load balancer, HTTPS).

I noted that the Docker image combines uWSGI and Nginx for Flask applications in Python running in a single container.

The repository topics include Debian, Docker, Flask, Nginx, Python, uWSGI, web, and webapp.

I can pin a Docker image version by selecting one of the date-specific tags, such as tiangolo/uwsgi-nginx-flask:python3.7-2019-10-14.

The repository is at https://github.com/tiangolo/uwsgi-nginx-flask-docker, and its Docker Hub image is at https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/.

For Kubernetes, Docker Swarm Mode, Nomad, and similar distributed container systems, I should handle replication at the cluster level instead of using a process manager in each container to start multiple worker processes.

For cluster deployments, the recommendation is to build an image from scratch, install dependencies, and run a single process instead of using this image.

The Gunicorn migration example starts from python:3.12, works in /code, installs /code/requirements.txt, copies the app into /code/app, and runs app.main:app with the supplied Gunicorn configuration.

The README says its remaining instructions are preserved mainly for historical reasons.

I do not have to clone the repository to use the image as a base image for other images.

The historical base-image example uses tiangolo/uwsgi-nginx-flask:python3.12, installs requirements from /app/requirements.txt, and copies the app into /app.

The historical instructions say new projects should use the latest available image version.

The base image has uWSGI and Nginx installed in the same container and was made to serve as the base for this image.

For the historical quick start, I create an app directory and put a file named main.py in it.

The Flask application object in the example is named app.

The example’s app.run section is for debugging purposes and uses debug=True and port=80; its host is redacted.

The historical quick-start commands are docker build -t myimage . and docker run -d --name mycontainer -p 80:80 myimage.

Modern frontend applications such as Vue, React, and Angular may compile ES2015 or TypeScript into JavaScript that is less modern and more compatible.

Serving compiled frontend code from the Flask container requires copying it into the container after compiling it.

Building the frontend this way requires frontend tools on the machine building the Docker image and remembering to compile the frontend beforehand.

The README calls adding compiled code to Git a very bad idea because it removes a single source of truth, can leave stale output, can cause branch conflicts, and can disrupt automatic pull-request branch merging.

The README recommends not serving frontend code from the same Flask Docker container.

The proposed alternative uses a separate container with frontend tools such as Node.js to compile source code, then uses Docker multi-stage builds to copy the distributable into a pure Nginx image.

The resulting frontend image contains compiled code generated from the source and is described as having the small size and performance of an Nginx image.

The README says Traefik can automatically generate HTTPS certificates using Let’s Encrypt for free and with an easy setup.

For a larger Python project, I put code in app/app/ and add an empty __init__.py there.

The app.main module refers to main.py in the app package at /app/app, and the Flask application object is named app.

When static files are in the same container, I can set STATIC_PATH to /app/app/static instead of its default /app/static.

From app/app/main.py, the example imports app_setup from app/app/core/app_setup.py with either from .core import app_setup or from app.core import app_setup.

From app/app/api/endpoints/user.py, the example imports users from app/app/core/database.py with from app.core.database import users.

For frontend routing, I can add a Flask catch-all route declared as @app.route("/<path:path>").

The route serves a requested file from the static folder when it exists; otherwise, it serves index.html so the frontend SPA can handle the URL.

During development, if Flask's debugging server is the container's only running process and it crashes, the container stops, making the error harder to inspect after restarting it.

docker run -d --name mycontainer -p 80:80 -v $(pwd)/app:/app -e FLASK_APP=main.py -e FLASK_DEBUG=1 myimage bash -c "while true ; do sleep 10 ; done"

For a package project, I set FLASK_APP=main/main.py rather than FLASK_APP=main.py.

The project says all image tags, configurations, environment variables, and application options are tested.

The project is licensed under the terms of the Apache license.