# Flask 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 `/health` route that returns 200, and set it as the app's health path in **Configuration**. - Read `SECRET_KEY` from 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](data-services.md). Files written inside the container are lost on the next deploy. - Use Gunicorn, as below. `flask run` is 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. ```dockerfile 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: ```sh 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](data-services.md): files written inside the container are lost on the next deploy. See also: [Flask deployment guidance](https://flask.palletsprojects.com/en/stable/deploying/gunicorn/).