# Free Gin hosting

Reverhost runs Gin, a fast HTTP framework for Go, 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 Gin builds and runs

| Step | What your Dockerfile runs |
| --- | --- |
| Build | `go build` with `CGO_ENABLED=0` in a build stage |
| Start | the compiled binary on `alpine:3.21` |
| Runtime env | `PORT=3000` and `HOSTNAME=0.0.0.0` from Reverhost, plus your own variables |

Run Gin in release mode and listen on `0.0.0.0` and `PORT`. The Go template works as is.

```main.go
package main

import (
	"os"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		c.JSON(200, gin.H{"hello": "Reverhost"})
	})
	r.Run("0.0.0.0:" + os.Getenv("PORT"))
}
```

## The Dockerfile

```Dockerfile
FROM golang:1.23-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN --mount=type=secret,id=appenv,target=/run/secrets/appenv sh -c 'set -a; . /run/secrets/appenv; set +a; CGO_ENABLED=0 go build -o /out/app .'

FROM alpine:3.21
RUN apk add --no-cache ca-certificates
COPY --from=build /out/app /app/app
ENV PORT=3000 GIN_MODE=release
EXPOSE 3000
CMD ["/app/app"]
```

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

## 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 pgx or `database/sql` with `os.Getenv("DATABASE_URL")`.

## Limits and caveats

A Go binary uses little memory, so Gin fits easily in 256 MB of RAM. Keep `ca-certificates` in the runtime image so TLS connections to Postgres and S3 work.

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

## Frequently asked questions

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

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