Blog / Tutorials / How to Self-Host Forgejo on a VPS with Docker

How to Self-Host Forgejo on a VPS with Docker

Forgejo is a community-governed, self-hosted Git forge with issues, pull requests, CI and a package registry. You can run it on a small VPS with Docker Compose in about ten minutes, using SQLite by default or PostgreSQL if you expect more than a handful of…

6 min read

Forgejo is a community-governed, self-hosted Git forge with issues, pull requests, CI and a package registry. You can run it on a small VPS with Docker Compose in about ten minutes, using SQLite by default or PostgreSQL if you expect more than a handful of users. This guide covers install, SSH, a reverse proxy and backups.

What Is Forgejo?

Forgejo is a self-hosted Git service, similar to GitHub or GitLab but running on your own server. It began as a soft fork of Gitea and is run by Codeberg e.V., a non-profit. That governance is the reason many people pick it.

You get repositories, issues, pull requests, a package registry and Forgejo Actions for CI. It’s a single Go application, so it’s light on resources. A small team can run it on a few gigabytes of RAM without drama.

Forgejo vs Gitea: Which Should You Pick?

They share a common ancestor and still look alike. The split is mostly governance and direction. Forgejo is community-run under a non-profit. Gitea is run by a company. If that distinction matters to you, it decides the question.

If it doesn’t, either works, and the practical differences are small enough that you’ll spend more time on backups than on the choice. We have a separate side-by-side comparison, so I won’t repeat the table here.

Forgejo System Requirements

Forgejo sizing by team size Author’s estimates for typical use, not benchmarks. Plan specs and prices from contabo.com/pricing on 27 November 2026 (24-month term, including VAT).
TeamReposSuggested planRAM
Solo or familyUp to about 50Cloud VPS 48 GB
Small team, with CI runners elsewhereUp to a few hundredCloud VPS 612 GB
Larger team, large repos, packagesMany, with big binariesCloud VPS 824 GB

Disk grows with repos, LFS files and packages, so plan for storage before CPU. If you’re looking for a self-hosted Git server for a few developers, the smallest plan is usually enough. Self hosted GitHub alternative setups only get heavy once CI runs on the same box.

How to Install Forgejo with Docker Compose

This is the Docker Compose file from the official Forgejo docs for version 17, which is current as of this writing (v15 is the long-term support line). It uses SQLite by default, so no database setup. Pin the major tag instead of using latest.

networks:
  forgejo:
    external: false

services:
  server:
    image: codeberg.org/forgejo/forgejo:17
    container_name: forgejo
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - FORGEJO__server__ROOT_URL=https://git.example.com/
      - FORGEJO__server__SSH_PORT=222
    restart: always
    networks:
      - forgejo
    volumes:
      - ./forgejo:/data
      - /etc/localtime:/etc/localtime:ro
    ports:
      - '3000:3000'
      - '222:22'

Port 222 on the host maps to SSH inside the container, because your VPS already uses port 22 for its own sshd. That’s why git clone URLs need the port, or an SSH config entry that sets it.

  1. Save the file as compose.yaml in an empty directory and run docker compose up -d.
  2. Open http://your-server-ip:3000 and finish the web installer. SQLite is preselected.
  3. Create the admin account during setup, or right after.
  4. Check that SSH_PORT and the domain on the installer page match your compose settings. Wrong values here mean wrong clone URLs later.
  5. Test with a clone over HTTPS and one over SSH on port 222.

There’s also a rootless image. Use the 17-rootless tag, run it as user 1000:1000, mount data at /var/lib/gitea, map host port 222 to container port 2222, and chown the data directory to 1000:1000 first. It’s a bit more fiddly and a bit safer.

Switch Forgejo to PostgreSQL and Put It Behind a Reverse Proxy

SQLite is fine for a small team. If you grow, or you want easier backups of a busy database, move to PostgreSQL. The official docs add a db service and a few variables. The sample passwords in the docs are all forgejo, so change them before anything touches the internet.

    environment:
      - FORGEJO__database__DB_TYPE=postgres
      - FORGEJO__database__HOST=db:5432
      - FORGEJO__database__NAME=forgejo
      - FORGEJO__database__USER=forgejo
      - FORGEJO__database__PASSWD=change-this
    depends_on:
      - db

  db:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER=forgejo
      - POSTGRES_PASSWORD=change-this
      - POSTGRES_DB=forgejo
    networks:
      - forgejo
    volumes:
      - ./postgres:/var/lib/postgresql/data

# Caddyfile: HTTPS in one block
git.example.com {
    reverse_proxy localhost:3000
}

The docs example uses postgres:14, which is old. I used 16 here; pick a version that’s still supported, and keep it fixed across upgrades. Caddy gets a Let’s Encrypt certificate on its own, which is why I like it for small servers.

Set Up Forgejo Actions Runner and Backups

Forgejo Actions runs your CI jobs through a separate runner process. Run it on a different machine or at least a different container from Forgejo, because CI jobs run arbitrary code and eat CPU. Registration steps are in the official runner docs and change between versions, so follow them for your release.

For backups, Forgejo has a forgejo dump command that packs the repositories, database and config into one archive. Run it on a schedule and copy the archive off the server. A backup you haven’t restored once is a guess, so restore it to a throwaway VPS before you need it.

Keep the server patched, too. Forgejo is an internet-facing application that holds your source code, and forge software has had serious vulnerabilities before. Subscribe to the project’s release announcements and update the image tag when security fixes land.

Why Run Forgejo on a Contabo VPS

A Git forge is storage-heavy and RAM-light, which suits a Contabo Cloud VPS. Cloud VPS 4 has 4 vCPU, 8 GB RAM and 100 GB SSD for €5.24 a month, and Cloud VPS 6 has 6 vCPU, 12 GB RAM and 200 GB SSD for €7.14. Prices are for a 24-month term including VAT and they change, so check the pricing page.

It’s unmanaged, so backups, updates and firewall rules are yours. For a self-hosted forge that’s the deal, and it’s why the cost stays low.

FAQ: Forgejo

Is Forgejo better than Gitea?

Neither is better in a general sense. They’re close cousins. Forgejo is governed by a non-profit and Gitea by a company, so the choice usually comes down to who you want steering the project. Both run well on a small VPS.

Can Forgejo replace GitHub for a small team?

For source hosting, issues, pull requests and CI, yes. You lose GitHub’s network effects and its ecosystem of hosted integrations. Many teams keep GitHub for public projects and run Forgejo for private code.

How much RAM does Forgejo need?

A small team can run Forgejo on 2 to 4 GB of RAM. The 8 GB Cloud VPS in this guide leaves comfortable headroom for the database and the OS. Heavy CI should run on a separate runner, not on the forge itself.

Does Forgejo support CI/CD?

Yes. Forgejo Actions runs workflows through a separate runner process. The syntax is close to GitHub Actions, though not identical, so expect to adjust existing workflow files.

Disclaimer: Product specifications, features, and prices mentioned in this article are subject to change and may vary by region, billing term, and active promotions. Please check each provider’s or brand’s official website for current figures, pricing, and local currency rates.