# Deploy Flask

Flask is detected from your dependencies and runs as a Python container on port `8000`. No Dockerfile needed - one is [generated](/platform/deployments/builds#dockerfiles-generated-or-your-own) unless the repo has its own.

## Serve it

Run a production server, not `flask run` - bind `0.0.0.0` on the routed [port](/create/build-settings#port):

```bash
gunicorn "app:create_app()" --bind 0.0.0.0:$PORT
```

(`app:app` for a module-level app object.)

## Configuration and database

Read [environment variables](/platform/environment-variables#build-time-and-runtime) at startup:

```python
import os

app.config["SECRET_KEY"] = os.environ["SECRET_KEY"]
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URL"]
```

`DATABASE_URL` comes from the [Credentials tab](/platform/databases/connect); keep `sslmode=require` in place. Flask-Migrate/Alembic runs where the database is reachable - startup command or laptop.

## Scaling

Sync Flask workers hold a request each - lower [concurrency](/create/scaling#concurrency) (`10`-`20`) matches a small Gunicorn worker count better than the default 80. [Scale to zero](/create/scaling#min-instances) covers idle time.

## Related

- [Python](/platform/frameworks/python): The runtime's defaults for any Python app.
- [Connect an app](/platform/databases/connect): DATABASE_URL, TLS, per-environment databases.
- [Scaling](/create/scaling): Matching concurrency to worker counts.
