# Free Axum hosting

Reverhost runs Axum, a Rust web framework built on Tokio, in an always-on container built from your Dockerfile, for $0. No credit card is needed, and your agent can deploy it with one instruction.

## What you get

- An always-on container with 256 MB of RAM with no swap, 0.5 CPU and images up to 1 GB
- A URL at `<app-slug>.easyhost.fun`, plus custom domains with HTTPS
- One Postgres 16 database and one S3 bucket per project
- 2 apps per project, with a 128 MB database and 256 MB of storage

## How Axum builds and runs

| Step | What your Dockerfile runs |
| --- | --- |
| Build | `cargo install --path .` in a build stage |
| Start | the compiled binary on `debian:bookworm-slim` |
| Runtime env | `PORT=3000` and `HOSTNAME=0.0.0.0` from Reverhost, plus your own variables |

Bind a Tokio listener to `0.0.0.0` and the `PORT` variable. The Rust template works as is.

```src/main.rs
use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let port: u16 = std::env::var("PORT").unwrap().parse().unwrap();
    let app = Router::new().route("/", get(|| async { "Hello from Reverhost" }));
    let listener = tokio::net::TcpListener::bind(("0.0.0.0", port)).await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
```

## The Dockerfile

```Dockerfile
FROM rust:1.83-slim AS build
WORKDIR /src
COPY . .
RUN --mount=type=secret,id=appenv,target=/run/secrets/appenv sh -c 'set -a; . /run/secrets/appenv; set +a; cargo install --path . --root /out && mv /out/bin/* /out/app'

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=build /out/app /app/app
ENV PORT=3000
EXPOSE 3000
CMD ["/app/app"]
```

Save it as `Dockerfile` in your project folder. It is based on the [Rust template](/languages/rust).

## Deploy it

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst build dockerfile set -f Dockerfile
npx ezhst env import .env
npx ezhst deploy
```

## Connect Postgres

```
npx ezhst db create main
npx ezhst db info --json
npx ezhst env set DATABASE_URL="postgresql://..."
npx ezhst redeploy
```

Use sqlx or tokio-postgres with `std::env::var("DATABASE_URL")`, and enable a TLS feature such as rustls.

## Limits and caveats

Compilation happens during the build, so even large crates run comfortably in 256 MB of RAM. Use rustls features in your database and HTTP clients to avoid OpenSSL in the runtime image.

Apps run in one region, with no edge network, preview deployments or Git integration. See [all frameworks](/frameworks) and [Rust hosting](/languages/rust).

## Frequently asked questions

### Is Axum hosting on Reverhost really free?

Yes. It costs $0 per month with no credit card and no trial period, within the published limits.

### Does my Axum app sleep when idle?

No. Reverhost apps run in an always-on container and do not sleep when idle.
