On this page
- What is Forgejo and what does it need?
- How do you write the Compose file?
- How do you start Forgejo and create the admin?
- How do you serve Forgejo over HTTPS with Caddy?
- How does SSH cloning work on port 2222?
- How do you set up mail and CI runners?
- How do you back up and upgrade Forgejo?
- What should you check when it does not work?
- Questions
What is Forgejo and what does it need?
Forgejo is a community-governed Git forge that grew out of Gitea and keeps a similar interface, with repositories, issues, pull requests, packages and its own Actions runner. Releases come as a stable line plus a long-term support line, and the container image is the most common way to run it.
- Ubuntu 24.04 or Debian 12/13 with Docker and the Compose plugin. The Docker app image has both ready, or see Docker Engine install.
- DNS for
code.example.net. - 1 GB of memory for a handful of users with PostgreSQL alongside; more if runners share the machine.
docker --version
docker compose version
sudo mkdir -p /opt/forgejo && cd /opt/forgejoHow do you write the Compose file?
Two services are enough: Forgejo itself and PostgreSQL on a private network, with settings injected as environment variables so no installer screen is needed.
services:
server:
image: codeberg.org/forgejo/forgejo:15
container_name: forgejo
restart: unless-stopped
depends_on: [db]
environment:
USER_UID: "1000"
USER_GID: "1000"
FORGEJO__database__DB_TYPE: postgres
FORGEJO__database__HOST: db:5432
FORGEJO__database__NAME: forgejo
FORGEJO__database__USER: forgejo
FORGEJO__database__PASSWD: ${DB_PASSWORD}
FORGEJO__server__ROOT_URL: https://code.example.net/
FORGEJO__server__DOMAIN: code.example.net
FORGEJO__server__SSH_DOMAIN: code.example.net
FORGEJO__server__SSH_PORT: "2222"
FORGEJO__security__INSTALL_LOCK: "true"
FORGEJO__service__DISABLE_REGISTRATION: "true"
volumes:
- ./data:/data
- /etc/localtime:/etc/localtime:ro
ports:
- "127.0.0.1:3000:3000"
- "2222:22"
db:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_USER: forgejo
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: forgejo
volumes:
- ./postgres:/var/lib/postgresql/dataThe tag 15 is an example of pinning a major release. Check the Forgejo releases page and choose the current LTS line for a quiet life or the current stable line for new features. Generate the database password into a private .env file next to the Compose file:
printf 'DB_PASSWORD=%s\n' "$(openssl rand -hex 24)" | sudo tee /opt/forgejo/.env
sudo chmod 600 /opt/forgejo/.envHow do you start Forgejo and create the admin?
Bring the stack up, wait for the database migration in the log, then create the first administrator with the built-in CLI as the git user inside the container.
cd /opt/forgejo
sudo docker compose up -d
sudo docker compose logs -f server
sudo docker exec -u git forgejo forgejo admin user create \
--admin --username deploy --email deploy@example.net --random-password
curl -s http://127.0.0.1:3000/api/healthzThe create command prints a random password; sign in with it and set your own at the first login. The health endpoint answers with a JSON status when the server and database are both reachable. Because INSTALL_LOCK is true, nobody can reach the web installer and overwrite the setup.
How do you serve Forgejo over HTTPS with Caddy?
Install Caddy from its official repository and add a site block that proxies to the loopback port; certificates are handled automatically.
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update && sudo apt install -y caddycode.example.net {
reverse_proxy 127.0.0.1:3000
}sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 2222/tcp
sudo ufw enable
sudo systemctl reload caddy
curl -I https://code.example.netDocker publishes 2222 on its own, ufw or not, but the explicit rule documents the intent. Caddy imposes no body size limit by default, so large pushes over HTTPS work without extra settings. If you would rather keep Nginx, the Nginx reverse proxy guide applies unchanged.
How does SSH cloning work on port 2222?
The container runs its own SSH daemon on port 22, which Compose maps to 2222 on the host, so clone URLs carry that port and your normal server SSH on 22 is untouched.
git clone ssh://git@code.example.net:2222/deploy/site.gitAdd your public key under Settings, SSH / GPG Keys first. To keep the shorter URL form on your own computer, add a host entry to ~/.ssh/config:
Host code.example.net
Port 2222
User gitAfter that, git clone code.example.net:deploy/site.git works. Because SSH_PORT is set to 2222, the clone box in the web interface already shows the right address.
How do you set up mail and CI runners?
Add mailer variables that point at an authenticated relay on port 587, and attach a Forgejo Runner (or another CI system) for workflows.
FORGEJO__mailer__ENABLED: "true"
FORGEJO__mailer__PROTOCOL: smtp+starttls
FORGEJO__mailer__SMTP_ADDR: smtp.example.net
FORGEJO__mailer__SMTP_PORT: "587"
FORGEJO__mailer__FROM: code@example.net
FORGEJO__mailer__USER: code@example.net
FORGEJO__mailer__PASSWD: ${SMTP_PASSWORD}Mail covers notifications, password resets and email confirmations. Port 25 is not promised open on a VPS, so ask support in a ticket before planning direct sending, and use a relay as above, with SMTP_PASSWORD added to the private .env file; SMTP relay for apps walks through it. Recreate the container with sudo docker compose up -d and send a test from Site administration.
For CI, enable Actions under Site administration and register a Forgejo Runner with a token from the repository or organisation settings. Running jobs on a second server keeps builds from slowing the forge. Woodpecker CI integrates with Forgejo as an alternative.
How do you back up and upgrade Forgejo?
Dump the database, archive the data folder, and upgrade by changing the image tag and recreating the container.
cd /opt/forgejo
sudo docker compose exec -T db pg_dump -U forgejo forgejo | gzip > /root/forgejo-db-$(date +%F).sql.gz
sudo tar -czf /root/forgejo-data-$(date +%F).tar.gz -C /opt/forgejo data
# upgrade: edit the image tag, then
sudo docker compose pull
sudo docker compose up -d
sudo docker exec forgejo forgejo --versionForgejo migrates the database on start, and downgrades are not supported, so keep the backup from before the upgrade until the new version runs cleanly. Read the release notes for breaking changes before a major jump. Copy the archives off the server; the daily backup add-on gives you a second, disk-level layer.
What should you check when it does not work?
Look at the container log first; Forgejo prints the config path and any database or permission error on start.
- Permission denied in /data:
USER_UIDandUSER_GIDdo not match the owner of./data. - Links in mail point to localhost:
ROOT_URLis unset or wrong. - SSH clone times out: port 2222 is blocked upstream of Docker or the URL lacks the port.
- Settings changes ignored: values in
data/gitea/conf/app.iniare rewritten from the environment at each start, so change the variable, not the file.
sudo docker compose logs --tail 100 server
sudo docker compose psPlans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Forgejo Git server
Is Forgejo compatible with Gitea?
It began as a fork and shares much of its design, but the projects have diverged. Moving from older Gitea versions is documented; check the Forgejo upgrade notes for your exact versions.
Should I pick the LTS or the stable release?
LTS suits a server you want to touch rarely. The stable line gets new features sooner but needs upgrades more often.
Can I install Forgejo without Docker?
Yes, a binary is published. The steps mirror the Gitea binary install: a git user, a systemd unit and a reverse proxy.
How much memory does it need?
About 1 GB with PostgreSQL for a few users. Runners, mirrors and the code search indexer are what raise the need.
Can I use SQLite?
Yes, set DB_TYPE to sqlite3 and drop the db service. It suits a personal forge; PostgreSQL is better once several people push at once.
More in Self-hosted apps
- Nextcloud on Nginx
- ownCloud Infinite Scale
- Seafile file sync
- Vaultwarden password vault
- Passbolt team password manager
- Gitea Git hosting
- GitLab Community Edition
- Gogs Git service
- Wiki.js
- BookStack documentation
- Outline knowledge base
- Paperless-ngx documents
- n8n workflow automation
- Activepieces automation
- Plausible Analytics (Community Edition)
- Umami analytics
- Mattermost team chat
- Matrix Synapse with Element
- Jitsi Meet video calls
- ONLYOFFICE Docs with Nextcloud
- HashiCorp Vault secrets server
- OpenBao secrets management
- Infisical secrets manager
- Authelia SSO and forward auth
- Zitadel identity platform
- VS Code in the browser (code-server)
- Joplin Server for notes sync
- Firefly III personal finance
- Snipe-IT asset tracking
- Odoo ERP on Ubuntu or Debian
- ERPNext with frappe_docker
- Dolibarr ERP and CRM with Nginx
- Penpot design tool with Docker
- Planka kanban boards
- Leantime project management
- Wekan boards with Docker
- Cal.com scheduling
- Chatwoot support inbox
- Mautic marketing automation
- DocuSeal document signing
- Metabase dashboards
- Appwrite backend server
- Self-hosted Supabase
- PocketBase backend
- RustDesk relay server
- Traccar GPS tracking
- Redmine project tracker
- The Lounge IRC client
- CyberChef data toolbox
- Typebot chat forms
- AFFiNE workspace
- Overleaf Community Edition
- Neko shared virtual browser
- imgproxy image resizing
- NetBox network inventory
- UVdesk help desk
- YetiForce CRM