Flask
Serve a Flask WSGI app using Gunicorn.
Deploy a Flask app with Gunicorn.
Prepare your app
This guide assumes app.py defines app. List flask and gunicorn in requirements.txt with pinned versions. If you use an application factory, change app:app in the start command to 'app:create_app()'.
- Add a
/healthroute that returns 200, and set it as the app's health path in Configuration. - Read
SECRET_KEYfrom an environment variable. If the app makes a new key each time it starts, everyone is signed out on every deploy. - Save uploads to a bucket or disk. Files written inside the container are lost on the next deploy.
- Use Gunicorn, as below.
flask runis for development only.
Build with a Dockerfile
This Dockerfile installs from requirements.txt with pip. If you use another
Python version or tool, such as Poetry or uv, change the base image and the
install line to match.
FROM python:3.14-slim-bookworm
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=3000
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY --chown=10001:10001 . .
USER 10001:10001
EXPOSE 3000
CMD ["sh", "-c", "exec gunicorn --bind 0.0.0.0:${PORT:-3000} --workers 1 --access-logfile - app:app"]
Deploy the app
Save the Dockerfile at the source root. Add a .dockerignore that excludes
.env*, .git, .venv and __pycache__, then deploy and check the health path:
smolcloud deploy APP_ID .
smolcloud request APP_ID /health
Then open the app and try a real page too. Read secrets from environment variables, and keep data in PostgreSQL or a bucket: files written inside the container are lost on the next deploy.
See also: Flask deployment guidance.