Skip to main content
To self-host a Git server with Forgejo, run the codeberg.org/forgejo/forgejo:17 image and a postgres:14 database with Docker Compose. Publish the web interface on 127.0.0.1:3000 behind Nginx with HTTPS, and Git over SSH on port 222. Open https://git.example.com, complete the initial configuration and create the administrator account.

What is Forgejo?

Forgejo is a free, self-hosted Git service, similar to GitHub or GitLab: repositories, issues, pull requests, packages and CI (Forgejo Actions) in one web app. It started as a fork of Gitea and is developed under the Codeberg umbrella.

Before you start

  • Install Docker. Forgejo’s upgrade guide asks for Docker 20.10.6 or newer.
  • Point git.example.com at your server. See point a domain to your server.
  • Install Nginx for HTTPS. The commands use sudo; leave it out if you are root.
  • Your server’s own SSH keeps port 22. Forgejo’s SSH listens on port 222 so the two don’t clash.

How to install Forgejo with Docker Compose

1

Create a folder and a database password

2

Create compose.yaml

This is the PostgreSQL example from the Forgejo Docker guide, with the password moved to .env, the web port bound to 127.0.0.1 and the SSH port shown in clone URLs set to 222:
FORGEJO__section__KEY variables write settings into Forgejo’s app.ini. The :17 tag follows the Forgejo 17 series; moving to the next major version is a deliberate tag change.
3

Start it

If codeberg.org is unreachable, the Forgejo docs say you can use data.forgejo.org/forgejo/forgejo:17 instead.

How to serve Forgejo over HTTPS with Nginx

1

Create the Nginx site

Create /etc/nginx/sites-available/git.example.com (Ubuntu / Debian) or /etc/nginx/conf.d/git.example.com.conf (AlmaLinux / Rocky):
client_max_body_size allows large pushes over HTTPS; raise it if you push bigger repositories.
2

Enable, test and reload

On AlmaLinux / Rocky, also run sudo setsebool -P httpd_can_network_connect 1.
3

Get a certificate

How to complete the initial configuration

1

Open the setup page

Open https://git.example.com. Forgejo shows its initial configuration page. The database settings are already filled in from compose.yaml.
2

Set the domain and URL

Set Server Domain to git.example.com and Forgejo Base URL to https://git.example.com/.
3

Create the administrator account

In the optional administrator account section, enter a username, email and strong password, then click the install button at the bottom of the page. The Forgejo docs recommend creating the administrator here, especially if you will disable self-registration.
4

Decide who can register

For a private server, disable self-registration. Add this line to the environment list of the server service and run sudo docker compose up -d:
Only administrators can then create accounts.
Complete the initial configuration as soon as the site is reachable. Until you do, whoever opens the page first can configure the server.

How to check it worked

Log in, add your public SSH key in your user settings and create a test repository called project. Then clone it from your computer:
The clone succeeds without asking for a password. If port 222 times out, allow TCP 222 in any firewall in front of the server; see check if a port is open from outside.

How to back up Forgejo

Forgejo recommends stopping it during a backup so files and database match. Back up the database with pg_dump and the ./forgejo folder, which holds repositories and app.ini (including the secret keys).
See the Forgejo backup guide and back up Docker volumes.

How to update Forgejo

Minor and patch releases arrive when you pull the same major tag:
For a new major version (for example 17 to 18), back up first, read the release notes’ upgrade section, then change the tag in compose.yaml and run the same two commands. The upgrade guide recommends going straight to the latest release and checking the result with forgejo doctor check --all.

Frequently asked questions

Forgejo or Gitea: which should I use?

Both run the same way in Docker. Forgejo is community-governed under Codeberg. If you are moving from Gitea, the Forgejo docs say to upgrade to Forgejo 10.0.x first, then to later versions.

Can I use SQLite instead of PostgreSQL?

Yes. If you leave out the database settings, Forgejo uses SQLite, which is fine for a few users. PostgreSQL suits larger or busier servers.

Why do clone URLs show port 22?

SSH_PORT sets the port shown in clone URLs. Check that FORGEJO__server__SSH_PORT=222 is in compose.yaml and recreate the container.

Can I run CI pipelines?

Yes, with Forgejo Actions. It needs a separate Forgejo Runner; see the Forgejo Actions docs.

VPS and dedicated server guides

Every guide in this section.

Create and use SSH keys

Make the key you add to Forgejo.

Nginx reverse proxy

How proxying to a local port works.

Update Docker containers

Pull new images safely.

Set up a firewall with UFW

Allow ports 80, 443 and 222.

Checked against the official Forgejo documentation on 4 November 2026 (image codeberg.org/forgejo/forgejo:17); compose.yaml validated with docker compose config and the Nginx configuration syntax-tested on Ubuntu 24.04 LTS. Settings can change between Forgejo major versions.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026