Meinheld managed by Gunicorn for WSGI web applications (Flask, Django) in Python 3.7 and 3.6.
100K+
This Docker image is now deprecated. Read about it below.
šØ 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:
python3.9python3.9-alpine3.13python3.8python3.8-alpine3.11python3.7python3.7-alpine3.8python3.6python3.6-alpine3.8python2.7The last date tags for these versions are:
python3.9-2025-11-09python3.9-alpine3.13-2024-03-11python3.8-2024-11-02python3.8-alpine3.11-2024-03-11python3.7-2024-11-02python3.7-alpine3.8-2024-03-11python3.6-2022-11-25python3.6-alpine3.8-2022-11-25python2.7-2022-11-25Note: There are tags for each build dateā . If you need to "pin" the Docker image version you use, you can select one of those tags. E.g. tiangolo/meinheld-gunicorn:python3.9-2024-11-02.
Dockerā image with Meinheldā managed by Gunicornā for high-performance web applications in Pythonā , with performance auto-tuning.
GitHub repo: https://github.com/tiangolo/meinheld-gunicorn-dockerā
Docker Hub image: https://hub.docker.com/r/tiangolo/meinheld-gunicorn/ā
Python web applications running with Meinheld controlled by Gunicorn have some of the best performances achievable by (older) Python frameworksā based on WSGI (synchronous code, instead of ASGI, which is asynchronous).
This applies to frameworks like Flask and Django.
Meinheld is a high-performance WSGI-compliant web server.
You can use Gunicorn to manage Meinheld and run multiple processes of it.
This image was created to be an alternative to tiangolo/uwsgi-nginxā .
And to be the base of tiangolo/meinheld-gunicorn-flaskā .
You are probably using Kubernetes or similar tools. In that case, you probably don't need this image (or any other similar base image). You are probably better off building a Docker image from scratch.
If you have a cluster of machines with Kubernetes, Docker Swarm Mode, Nomad, or other similar complex system to manage distributed containers on multiple machines, then you will probably want to handle replication at the cluster level instead of using a process manager in each container that starts multiple worker processes, which is what this Docker image does.
In those cases (e.g. using Kubernetes) you would probably want to build a Docker image from scratch, installing your dependencies, and running a single process instead of this image.
For example, using Gunicornā you could have a file app/gunicorn_conf.py with:
# Gunicorn config variables
loglevel = "info"
errorlog = "-" # stderr
accesslog = "-" # stdout
worker_tmp_dir = "/dev/shm"
graceful_timeout = 120
timeout = 120
keepalive = 5
threads = 3
And then you could have a Dockerfile with:
FROM python:3.14
WORKDIR /code
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", "0.0.0.0:80", "app.main:app"]
You can read more about these ideas in the FastAPI documentation about: FastAPI in Containers - Dockerā as the same ideas would apply to other web applications in containers.
Meinheldā has not been actively maintained in the past years.
The current latest version of Meinheld released is 1.0.2, from May 17, 2020. This version of Meinheld requires an old version of Greenlet (>=0.4.5,<0.5) that is not compatible with Python 3.10 and 3.11, the last version compatible was Python 3.9.
Python 3.9 reached its End Of Lifeā . So, there is currently no feasible way to use Meinheld.
Additionally, most of my time is now dedicated to FastAPIā and friends.
Because of all that, this Docker image is no longer supported. āļø
The rest of the README is preserved mainly for historical reasons.
You don't have to clone this repo.
You can use this image as a base image for other images.
Assuming you have a file requirements.txt, you could have a Dockerfile like this:
FROM tiangolo/meinheld-gunicorn:python3.9
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
COPY ./app /app
It will expect a file at /app/app/main.py.
Or otherwise a file at /app/main.py.
And will expect it to contain a variable app with your "WSGI" application.
Then you can build your image from the directory that has your Dockerfile, e.g:
docker build -t myimage ./
These are the environment variables that you can set in the container to configure it and their default values:
MODULE_NAMEThe Python "module" (file) to be imported by Gunicorn, this module would contain the actual application in a variable.
By default:
app.main if there's a file /app/app/main.py ormain if there's a file /app/main.pyFor example, if your main file was at /app/custom_app/custom_main.py, you could set it like:
docker run -d -p 80:80 -e MODULE_NAME="custom_app.custom_main" myimage
VARIABLE_NAMEThe variable inside of the Python module that contains the WSGI application.
By default:
appFor example, if your main Python file has something like:
from flask import Flask
api = Flask(__name__)
@api.route("/")
def hello():
return "Hello World from Flask"
In this case api would be the variable with the "WSGI application". You could set it like:
docker run -d -p 80:80 -e VARIABLE_NAME="api" myimage
APP_MODULEThe string with the Python module and the variable name passed to Gunicorn.
By default, set based on the variables MODULE_NAME and VARIABLE_NAME:
app.main:app ormain:appYou can set it like:
docker run -d -p 80:80 -e APP_MODULE="custom_app.custom_main:api" myimage
GUNICORN_CONFThe path to a Gunicorn Python configuration file.
By default:
/app/gunicorn_conf.py if it exists/app/app/gunicorn_conf.py if it exists/gunicorn_conf.py (the included default)You can set it like:
docker run -d -p 80:80 -e GUNICORN_CONF="/app/custom_gunicorn_conf.py" myimage
WORKERS_PER_COREThis image will check how many CPU cores are available in the current server running your container.
It will set the number of workers to the number of CPU cores multiplied by this value.
By default:
2You can set it like:
docker run -d -p 80:80 -e WORKERS_PER_CORE="3" myimage
If you used the value 3 in a server with 2 CPU cores, it would run 6 worker processes.
You can use floating point values too.
So, for example, if you have a big server (let's say, with 8 CPU cores) running several applications, and you have an ASGI application that you know won't need high performance. And you don't want to waste server resources. You could make it use 0.5 workers per CPU core. For example:
docker run -d -p 80:80 -e WORKERS_PER_CORE="0.5" myimage
In a server with 8 CPU cores, this would make it start only 4 worker processes.
WEB_CONCURRENCYOverride the automatic definition of number of workers.
By default:
WORKERS_PER_CORE. So, in a server with 2 cores, by default it will be set to 4.You can set it like:
docker run -d -p 80:80 -e WEB_CONCURRENCY="2" myimage
This would make the image start 2 worker processes, independent of how many CPU cores are available in the server.
HOSTThe "host" used by Gunicorn, the IP where Gunicorn will listen for requests.
It is the host inside of the container.
So, for example, if you set this variable to 127.0.0.1, it will only be available inside the container, not in the host running it.
It's is provided for completeness, but you probably shouldn't change it.
By default:
0.0.0.0PORTThe port the container should listen on.
If you are running your container in a restrictive environment that forces you to use some specific port (like 8080) you can set it with this variable.
By default:
80You can set it like:
docker run -d -p 80:8080 -e PORT="8080" myimage
BINDThe actual host and port passed to Gunicorn.
By default, set based on the variables HOST and PORT.
So, if you didn't change anything, it will be set by default to:
0.0.0.0:80You can set it like:
docker run -d -p 80:8080 -e BIND="0.0.0.0:8080" myimage
LOG_LEVELThe log level for Gunicorn.
One of:
debuginfowarningerrorcriticalBy default, set to info.
If you need to squeeze more performance sacrificing logging, set it to warning, for example:
You can set it like:
docker run -d -p 80:8080 -e LOG_LEVEL="warning" myimage
The image includes a default Gunicorn Python config file at /gunicorn_conf.py.
It uses the environment variables declared above to set all the configurations.
You can override it by including a file in:
/app/gunicorn_conf.py/app/app/gunicorn_conf.py/gunicorn_conf.py/app/prestart.shIf you need to run anything before starting the app, you can add a file prestart.sh to the directory /app. The image will automatically detect and run it before starting everything.
For example, if you want to add Alembic SQL migrations (with SQLAlchemy), you could create a ./app/prestart.sh file in your code directory (that will be copied by your Dockerfile) with:
#! /usr/bin/env bash
# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head
and it would wait 10 seconds to give the database some time to start and then run that alembic command.
If you need to run a Python script before starting the app, you could make the /app/prestart.sh file run your Python script, with something like:
#! /usr/bin/env bash
# Run custom Python script before starting
python /app/my_custom_prestart_script.py
In short: You probably shouldn't use Alpine for Python projects, instead use the slim Docker image versions.
Do you want more details? Continue reading š
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.
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. š©
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. š¤Æ
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. š³
If you want slim Python images, you should instead try and use the slim versions that are still based on Debian, but are smaller. š¤
All the image tags, configurations, environment variables and application options are tested.
*.pyc files with PYTHONDONTWRITEBYTECODE=1 and ensure logs are printed immediately with PYTHONUNBUFFERED=1. PR #109ā by @estebanx64ā .EXPOSE 80 by default as the port can be changed. PR #128ā by @tiangoloā .issue-manager.yml. PR #127ā by @tiangoloā .latest-changes GitHub Action. PR #126ā by @tiangoloā .latest-changes.yml. PR #114ā by @alejsdevā .README.md. PR #113ā by @alejsdevā .README.md. PR #112ā by @alejsdevā .Highlights of this release:
python3.6-2022-11-25 and python2.7-2022-11-25.--no-cache-dir to reduce disk size used. PR #38ā by @tiangoloā .Content type
Image
Digest
sha256:8c3fd3573ā¦
Size
358.1 MB
Last updated
11 months ago
docker pull tiangolo/meinheld-gunicorn