# Free Ruby hosting

Run Ruby, a dynamic language built for developer happiness, in an always-on container built from your Dockerfile. Start from the Ruby template, deploy with the CLI and add Postgres and storage for $0.

## What you can run

Any Ruby web app or API that listens on HTTP, including Rails, Sinatra, Hanami and Roda.

- [Rails](/free-rails-hosting)

## The starter Dockerfile

This is the `ruby` template, exactly as `ezhst build dockerfile template ruby` prints it.

```Dockerfile
FROM ruby:3.3-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
COPY Gemfile Gemfile.lock* ./
RUN bundle config set without development:test && bundle install
COPY . .
ENV RACK_ENV=production PORT=3000
EXPOSE 3000
CMD ["sh", "-c", "exec bundle exec rackup -o 0.0.0.0 -p $PORT"]
```

## Adapt it to your app

The template runs `bundle install` without development and test gems, then starts any Rack app with `rackup -o 0.0.0.0 -p $PORT`. For Rails, use the Rails Dockerfile, which precompiles assets and starts Puma.

- Listen on `0.0.0.0` and the `PORT` variable, which is `3000`. A server bound to localhost never receives traffic.
- Your variables are runtime env in the container. If a build command needs them, run it in a `RUN` step that mounts the `appenv` secret, as the template does. See [build-time environment variables](/guides/build-time-environment-variables).
- Never put secrets in `ARG` or `ENV`, because they end up in the image.

```config.ru
run ->(env) { [200, { "content-type" => "text/plain" }, ["Hello from Reverhost"]] }
```

## Deploy it

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst build dockerfile template ruby --apply
npx ezhst env import .env
npx ezhst deploy
```

`--apply` saves the template to the app. To use an edited copy instead, save it as `Dockerfile` and run `npx ezhst build dockerfile set -f Dockerfile`. Read [how to write a Dockerfile for Reverhost](/guides/write-a-dockerfile) for the general rules.

## Limits

Each app gets 256 MB of RAM with no swap, 0.5 CPU and images up to 1 GB. A project holds 2 apps, a 128 MB Postgres database and 256 MB of S3 storage. One build runs at a time per app, with up to 10 builds a day on the free plan. See [pricing and limits](/pricing).

## Connect Postgres and S3

```
npx ezhst db create main
npx ezhst db info --json
npx ezhst storage create files
npx ezhst storage info --json
```

Add the `pg` gem and read `ENV["DATABASE_URL"]`. Install `libpq-dev` in the Dockerfile so the gem can compile. Use the aws-sdk-s3 gem with `endpoint: "https://storage.reverhost.com"`, `region: "us-east-1"` and `force_path_style: true`. See the [Postgres](/products/postgres) and [storage](/products/storage) product pages.

## Frequently asked questions

### Is Ruby hosting on Reverhost free?

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

### Is a Dockerfile in my repository used automatically?

No. The Dockerfile is stored on the app. Save it with `ezhst build dockerfile set -f Dockerfile`, or apply a template, before you deploy.

### Which Ruby version runs my app?

The one in your Dockerfile's `FROM` line. The template starts from `ruby:3.3-slim`.
