# Free Rails hosting

Reverhost runs Rails, a full-stack Ruby web framework, 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 Rails builds and runs

| Step | What your Dockerfile runs |
| --- | --- |
| Build | `bundle install`, then `rails assets:precompile` |
| Start | `rails server -b 0.0.0.0 -p $PORT` |
| Runtime env | `PORT=3000` and `HOSTNAME=0.0.0.0` from Reverhost, plus your own variables |

Set `SECRET_KEY_BASE` (or `RAILS_MASTER_KEY`) and `DATABASE_URL`. Rails reads `DATABASE_URL` automatically. Set `RAILS_SERVE_STATIC_FILES=1` on Rails versions that do not serve `public` by default.

```config/puma.rb
threads 3, 3
port ENV.fetch("PORT")
workers 0
```

## The Dockerfile

```Dockerfile
FROM ruby:3.3-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends build-essential libpq-dev libyaml-dev && rm -rf /var/lib/apt/lists/*
ENV RAILS_ENV=production BUNDLE_WITHOUT=development:test PORT=3000
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
EXPOSE 3000
CMD ["sh", "-c", "exec bundle exec rails server -b 0.0.0.0 -p $PORT"]
```

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

## Deploy it

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst env set SECRET_KEY_BASE=<secret> RAILS_LOG_TO_STDOUT=1
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
```

Add the `pg` gem and read `ENV["DATABASE_URL"]`. Install `libpq-dev` in the Dockerfile so the gem can compile.

## Limits and caveats

Rails is memory hungry, so run a single Puma process with a few threads to stay inside 256 MB of RAM. Run `rails db:migrate` from your machine with `DATABASE_URL` set.

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

## Frequently asked questions

### Is Rails 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 Rails app sleep when idle?

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