1. Prepare the Server
Order a VPS with Ubuntu 24.04, secure it, and install Docker. Point an A record such as git.example.com at it, and allow ports 80, 443 and 222 in the firewall.
2. Write the Compose File
In ~/forgejo, create the data folder owned by the user the container runs as, then compose.yaml:
mkdir -p ~/forgejo/data && cd ~/forgejo sudo chown 1000:1000 data
services:
forgejo:
image: codeberg.org/forgejo/forgejo:17
container_name: forgejo
restart: always
environment:
- USER_UID=1000
- USER_GID=1000
volumes:
- ./data:/data
- /etc/localtime:/etc/localtime:ro
ports:
- "222:22" # Git over SSH
caddy:
image: caddy:2
container_name: caddy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy-data:/data
- ./caddy-config:/config# Caddyfile
git.example.com {
reverse_proxy forgejo:3000
}The number in the image tag is Forgejo's major version and follows its minor updates; 17 was current when this was written. Moving to the next major version needs a manual step, so check Forgejo's release notes first.
docker compose up -d docker compose logs -f
3. Finish the Setup Page
Open https://git.example.com. On the first page:
- Database: SQLite3 is fine for a team; it lives in the data folder.
- Server domain:
git.example.com; SSH server port:222. - Base URL:
https://git.example.com/. - Under the optional settings, disable self-registration unless the server is meant to be public.
- Create the administrator account in the last section.
4. Push Over SSH
Add your public key under Settings → SSH / GPG keys, then clone with the port in the address:
git clone ssh://[email protected]:222/you/project.git
Or let plain addresses work by adding this to ~/.ssh/config on your computer:
Host git.example.com
Port 222
User git5. CI With Forgejo Actions
Forgejo Actions reads workflow files much like GitHub Actions, and runs them on a separate program, Forgejo Runner. Install it on the same server for light use, or on a second, larger server so builds never slow the Git server down, and register it with a token from Site administration → Actions → Runners. The same reasoning as for a self-hosted GitHub runner applies: a runner with Docker access is effectively root on its server, so keep it to code you trust.
Backups and Updates
Repositories, the database, attachments and settings are all in ~/forgejo/data. For a clean copy, stop Forgejo for the moment it takes to archive it:
cd ~/forgejo docker compose stop forgejo sudo tar czf /var/backups/forgejo-$(date +%F).tar.gz data docker compose start forgejo
Then send the archive off the server, to a storage box or with Borg, from a nightly timer. Update within the major version with docker compose pull && docker compose up -d, after a backup.