GuidesDevelopers and hostingGit server with Forgejo

Run your own Git server with Forgejo and rootless Docker

Forgejo on Debian 13, a Git server with a web interface, issues, pull requests and CI, in rootless Docker under a user of its own, with a separate user for CI jobs and a first push for Git newcomers.

Tested on Docker steps follow the tested rootless Docker base guide on Debian 13 with Docker Engine 29.10.1, Compose 5.8.1 and rootlesskit 3.3.0; the app version and app-specific behaviour are from the tested Podman guide on a Melonslab server. Not re-tested end to end under Docker. Updated November 28, 2026

Recommended server for this guide

SSD RAID 1 · ECC DDR4 · 10 Gbit

VC-P Alloy · 2 vCPU · 8 GB Memory · 60 GB Storage

Month to month, no lock-in 7-day money-back guarantee

€8.99/mo

Deploy now

Quick install on a fresh VM

This command sets up a rootless container engine and a directory for this service. Podman is the default; add --engine docker to the command to use Docker instead.

curl -fsSL https://www.melonslab.com/install/rootless.sh | bash -s -- --app forgejo-docker --manifest forgejo --sha256 993c72f3bc6f16d96a8689ea7a85626fa804c4564c3ce51ebe4f336a9b5ad68b
View the script

SHA-256: 97785be3e3e91393181a4a7caeab5f4b52803bf52e960dd488945cb38c6473a2

Run this guide on Melonslab

We ran every step below on our own server. For this workload we recommend VC-P Alloy at €8.99/mo. Order it, pick Debian 13, and follow the guide.

  1. 1. Order the server. Use the button below to order the recommended plan. Choose Debian 13 when the installer asks for an operating system.
  2. 2. Add IPv4 if needed. Add it on the order form when the guide publishes a service on the internet. It is a paid add-on, not included in the plan.
  3. 3. Connect over SSH. Log in as root with the address and credentials from your order, then run the commands below.
  4. 4. Follow the verified steps. Every command in this guide was run on a Melonslab server before it was published.
Deploy now
On this page

What you will set up

Forgejo is a Git server with a web interface, much like GitHub: repositories, issues, pull requests, and Forgejo Actions, which runs your tests and builds on every push, with workflows much like GitHub's.

This Docker version follows the tested rootless Docker base guide on Debian 13. Under it, Forgejo runs as a Compose service under two users of their own:

  • forgejo runs Forgejo itself, in one container, with its database inside. The web interface sits behind Caddy from the Docker guide, and Git connects over SSH on port 2222.
  • runner runs the Forgejo Runner, which starts a fresh rootless container for each CI job. Jobs run code from your repositories, so they get a user of their own: a job cannot touch Forgejo's files or any other app on the server.

New to Git? Step 9 shows how to put code on the server, and what to do when Git refuses.

The app-specific results below come from the tested Podman guide on a Melonslab VC-P Alloy (2 vCPU, 8 GB) with Debian 13; they were not measured again under Docker. In that test:

  • From a laptop, a repository was cloned over SSH, changed and pushed, and an existing folder was pushed as a new repository.
  • A push that Git refused, because of a change from another computer, went through after git pull, also when both had changed the same line.
  • A workflow checked out the code and ran in the runner's containers, and a cache it saved was restored on the next run.
  • Forgejo logged the real address behind a failed login, and CI jobs could not reach apps that listen only on the server's loopback address.
  • Logins survived restarts of Forgejo and a reboot, and everything came back by itself.

In that test, Forgejo used about 120 MB of memory, and the runner 35 MB between jobs.

Before you start

You need:

  • a server set up as in the Docker guide, with Caddy running;
  • ufw switched on as in the security guide. Job containers get addresses of their own, which the firewall keeps closed to the internet;
  • an A record and an AAAA record for git.example.com pointing at your server.

The examples use git.example.com, anna as your user name and 203.0.113.10 for your server's IPv4 address. Replace them with your own throughout.

1. Open the SSH port for Git

Port 22 is the server's own SSH, so Forgejo's SSH server listens on 2222. As root:

ufw allow 2222/tcp

2. Create the user

useradd -m -s /bin/bash forgejo
loginctl enable-linger forgejo
uid=$(id -u forgejo)

The uid is looked up so the commands below work for any user. Keep it in this shell.

3. Create the secret key

Forgejo encrypts some of what it stores with a secret key, such as the secrets behind two-factor logins. Store it in an environment file only forgejo can read:

mkdir -p /home/forgejo/forgejo/data
printf 'FORGEJO__security__SECRET_KEY=%s\n' "$(openssl rand -hex 32)" > /home/forgejo/forgejo/forgejo.env
chmod 600 /home/forgejo/forgejo/forgejo.env
chown forgejo:forgejo /home/forgejo/forgejo/forgejo.env

4. Describe the container

As root, create /home/forgejo/forgejo/compose.yaml:

services:
  forgejo:
    image: codeberg.org/forgejo/forgejo:15-rootless
    container_name: forgejo
    env_file:
      - ./forgejo.env
    environment:
      FORGEJO__security__INSTALL_LOCK: "true"
      FORGEJO__security__REVERSE_PROXY_TRUSTED_PROXIES: "127.0.0.0/8,::1/128,203.0.113.10/32"
      FORGEJO__server__DOMAIN: git.example.com
      FORGEJO__server__ROOT_URL: https://git.example.com/
      FORGEJO__server__SSH_DOMAIN: git.example.com
      FORGEJO__server__SSH_PORT: "2222"
      FORGEJO__service__DISABLE_REGISTRATION: "true"
      FORGEJO__session__PROVIDER: db
    volumes:
      - /home/forgejo/forgejo/data:/var/lib/gitea
    # SSH for Git, open to the internet
    ports:
      - "2222:2222"
      # Web interface, reached through Caddy only
      - "127.0.0.1:8089:3000"
    restart: always

Each FORGEJO__ setting is the same one the Podman guide passed to the container:

  • INSTALL_LOCK skips the setup page, which anyone could otherwise use to take over a fresh Forgejo before you do.
  • Visitors reach Forgejo through Caddy, and those connections arrive in the container from the server's own IPv4 address. REVERSE_PROXY_TRUSTED_PROXIES includes it, so Forgejo logs each visitor's real address, which Caddy passes on.
  • DISABLE_REGISTRATION means nobody can sign up by themselves: you create the accounts.
  • session__PROVIDER=db keeps logins in Forgejo's database. By default they are kept in memory, and every restart of Forgejo, including the weekly updates in step 11, logs out everyone who did not tick Remember this device.

Forgejo writes these settings into its settings file, /var/lib/gitea/custom/conf/app.ini in the bind-mounted data directory, each time it starts. Changing a line changes the setting, but removing a line does not: the value stays in app.ini. To remove a setting afterwards, edit that file with the command below, delete its line, and restart:

chown -R forgejo:forgejo /home/forgejo/forgejo
runuser -u forgejo -- env HOME=/home/forgejo XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/forgejo/forgejo && docker compose exec forgejo vi /var/lib/gitea/custom/conf/app.ini && docker compose restart forgejo'

Everything Forgejo stores, including its SQLite database, lives in /home/forgejo/forgejo/data. SQLite is plenty for a person, a family or a small team. 15-rootless is Forgejo's long-term support (LTS) release, with fixes until July 2027. Forgejo 16 is newer, but a release without LTS gets fixes for only about three months, 16 until the end of October 2026, so you would change the tag every quarter. The next LTS release, Forgejo 19, is planned for April 2027.

Start it as the user:

runuser -u forgejo -- env HOME=/home/forgejo XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/forgejo/forgejo && docker compose up -d && docker compose logs forgejo'

The log ends with Starting new Web server: tcp:0.0.0.0:3000.

5. Put Caddy in front

As root, switch to runuser -u caddy -- /bin/bash, and add this block to the end of ~/Caddyfile:

git.example.com {
    reverse_proxy 127.0.0.1:8089
}

Restart Caddy with docker compose restart caddy from /home/caddy/caddy as caddy.

6. Create your account

As root, run this as forgejo:

runuser -u forgejo -- env HOME=/home/forgejo XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/forgejo/forgejo && \
    docker compose exec forgejo forgejo admin user create --admin --username anna --email anna@example.com --random-password'

It prints generated random password is '...'. Log in at https://git.example.com with it, and Forgejo asks you to choose your own. Create accounts for other people the same way, without --admin, or from the administration pages in the web interface.

7. Set up the runner for Forgejo Actions

Skip steps 7 and 8 if you do not need CI. As root, install Git, which the runner needs, and download the runner. The runner is one program, and Forgejo signs each release, so check the signature before you install it:

apt install -y git gpg curl
v=13.2.0
url=https://code.forgejo.org/forgejo/runner/releases/download/v$v/forgejo-runner-$v-linux-amd64
curl -fL -o forgejo-runner $url
curl -fL -o forgejo-runner.asc $url.asc
gpg --keyserver hkps://keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
gpg --verify forgejo-runner.asc forgejo-runner

The last command must print Good signature from "Forgejo <contact@forgejo.org>". A warning that the key is not certified is expected. 13.2.0 was the newest version when we wrote this; code.forgejo.org/forgejo/runner/releases lists newer ones. Install it, and create the user:

install -m 755 forgejo-runner /usr/local/bin/forgejo-runner
rm forgejo-runner forgejo-runner.asc
useradd -m -s /bin/bash runner
loginctl enable-linger runner

The runner starts each job's container through this user's rootless Docker daemon, set up as in the Docker guide. Its service unit below points at that user's socket.

Jobs usually start by fetching your code from https://git.example.com, which is this server. Docker gives job containers addresses of their own on a bridge network, so they can reach the server's public address and Forgejo on it. No extra container configuration is needed; this only applies to the runner user, so Forgejo's own settings, such as REVERSE_PROXY_TRUSTED_PROXIES, stay as they are.

Then generate the runner's configuration as runner:

runner_uid=$(id -u runner)
runuser -u runner -- env HOME=/home/runner XDG_RUNTIME_DIR=/run/user/$runner_uid \
  PATH=/usr/bin:/bin bash -lc 'forgejo-runner generate-config > ~/runner-config.yml && chmod 600 ~/runner-config.yml'

Open /home/runner/runner-config.yml in an editor, such as nano /home/runner/runner-config.yml, and replace the line labels: [] with:

  labels:
    - docker:docker://data.forgejo.org/oci/node:24-trixie
    - ubuntu-latest:docker://data.forgejo.org/oci/node:24-trixie

Keep the two spaces at the start of the first line. A workflow picks its runner with runs-on:, and both names run the job in Debian 13 with Node.js, Git and Python.

8. Connect the runner

In Forgejo, open https://git.example.com/admin/actions/runners and choose Create new runner. Name it, for example server-runner, and choose Create. Forgejo shows a block that starts with server:, with the runner's token, once. In /home/runner/runner-config.yml, delete everything from the line server: to the end of the file, and paste the block in its place.

As root, create ~/.config/systemd/user/forgejo-runner.service for the runner user:

mkdir -p /home/runner/.config/systemd/user
cat > /home/runner/.config/systemd/user/forgejo-runner.service <<'UNIT'
[Unit]
Description=Forgejo Runner, which runs Forgejo Actions jobs in rootless Docker
After=docker.service
Wants=docker.service

[Service]
ExecStart=/usr/local/bin/forgejo-runner daemon -c %h/runner-config.yml
Environment=DOCKER_HOST=unix:///run/user/%U/docker.sock
WorkingDirectory=%h
Restart=always
RestartSec=10
TimeoutStopSec=infinity

[Install]
WantedBy=default.target
UNIT
chown -R runner:runner /home/runner/.config

Start it:

runuser -u runner -- env XDG_RUNTIME_DIR=/run/user/$runner_uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$runner_uid/bus PATH=/usr/bin:/bin \
  systemctl --user daemon-reload
runuser -u runner -- env XDG_RUNTIME_DIR=/run/user/$runner_uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$runner_uid/bus PATH=/usr/bin:/bin \
  systemctl --user enable --now forgejo-runner
runuser -u runner -- env XDG_RUNTIME_DIR=/run/user/$runner_uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$runner_uid/bus PATH=/usr/bin:/bin \
  journalctl --user -u forgejo-runner

The log says declared successfully, and the runner page in Forgejo shows it as Idle. After changing runner-config.yml, use systemctl --user restart forgejo-runner. There is no reload: with Runner 13.2 it stopped the runner in our tests. The runner guide goes further, with tests, artifacts, container images and deploys.

9. Push your first code

This part is on your own computer. Git keeps the whole history of a project on your computer, and git push sends it to Forgejo.

Install Git. On Windows, install Git for Windows from git-scm.com. On macOS, run git --version in Terminal and accept the offer to install it. On Linux, install the git package, for example with sudo apt install git.

Tell Git who you are, once, in a terminal (on Windows, in PowerShell or Git Bash):

git config --global user.name "Anna Andersson"
git config --global user.email anna@example.com
git config --global init.defaultBranch main
git config --global pull.rebase true

Your name and address go on every change you save. The third line names your first branch main, as Forgejo does. The last one is explained under "When Git refuses" below.

Add your SSH key to Forgejo. Use the key from step 1 of the security guide, or make one with ssh-keygen -t ed25519. Show the public key:

cat ~/.ssh/id_ed25519.pub

In Forgejo, open your avatar's menu at the top right, choose Settings, then SSH / GPG keys and Add key. Paste the whole line, starting with ssh-ed25519, and choose Add key.

Create a repository. Choose + at the top right, then New repository. Name it hello, tick Initialize repository, and choose Create repository.

Copy it to your computer:

git clone ssh://git@git.example.com:2222/anna/hello.git
cd hello

The repository's page shows the same address when you choose SSH. The first time, SSH asks whether you trust the server: type yes.

Change something and send it. Open README.md in any editor, add a line and save it. Then:

git add README.md
git commit -m "Say hello"
git push

git add picks the changes to save, git commit saves them as one step in the history, on your computer, and git push sends your new steps to Forgejo. Reload the repository's page to see the change. git status shows what you have changed and not yet saved.

Put a folder you already have on Forgejo. Create a repository as above, but leave Initialize repository unticked, so it is empty. In the folder:

git init
git add .
git commit -m "First commit"
git remote add origin ssh://git@git.example.com:2222/anna/myproject.git
git push -u origin main

After the first push, git push is enough. To get changes made elsewhere, such as on another computer, run git pull.

When Git refuses

! [rejected] main -> main (fetch first). Forgejo has changes you do not have yet, for example from your other computer. Run git pull, then git push again. With pull.rebase set as above, git pull puts your new steps after the ones from Forgejo.

CONFLICT after git pull. You and the other change edited the same lines. Git marks them in the file, between <<<<<<< and >>>>>>>. Edit the file to keep what you want and remove the marker lines, then run git add with the file's name and git rebase --continue. If Git opens an editor with the step's message, save and close it. Then git push. git rebase --abort undoes the whole git pull instead.

error: src refspec main does not match any. There is nothing to push yet. Run git add and git commit first.

Permission denied (publickey). Forgejo did not accept your key. Check it is added under SSH / GPG keys, and that the address starts with ssh://git@: every account uses git, and Forgejo tells them apart by their key.

10. Run a workflow

In a repository, create .forgejo/workflows/test.yml:

on: [push]
jobs:
  test:
    runs-on: docker
    steps:
      - uses: actions/checkout@v5
      - run: ls

Add, commit and push it. The repository's Actions tab shows the run, and each step's output. Many workflows written for GitHub run as they are, with runs-on: ubuntu-latest. That runs on this runner too, in the same Debian image, which has less software installed than GitHub's own machines.

11. Keep it up to date

Add the weekly update timer from the Docker guide and test it once:

runuser -u forgejo -- env XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  systemctl --user enable --now docker-update.timer
runuser -u forgejo -- env XDG_RUNTIME_DIR=/run/user/$uid \
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
  systemctl --user start docker-update.service

The timer runs docker compose pull and docker compose up -d from /home/forgejo/forgejo. The 15-rootless tag gets every fix within Forgejo 15. Moving to the next long-term release is a change to the tag you make yourself, after reading Forgejo's release notes. For a new runner version, repeat the download in step 7 with its number, then run systemctl --user restart forgejo-runner as runner. The runner downloads the job image once and then keeps it; as runner, docker pull data.forgejo.org/oci/node:24-trixie gets the newest.

12. Back up

As root:

umask 077
mkdir -p /root/backup
runuser -u forgejo -- env HOME=/home/forgejo XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/forgejo/forgejo && docker compose stop'
tar -czf /root/backup/forgejo.tar.gz -C /home/forgejo forgejo
runuser -u forgejo -- env HOME=/home/forgejo XDG_RUNTIME_DIR=/run/user/$uid \
  DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
  bash -lc 'cd /home/forgejo/forgejo && docker compose start'

That saves every repository, the database and Forgejo's settings. The settings include forgejo.env with the secret key in plain text, and the keys of Forgejo's SSH server. Anyone with the archive can read all your code and what Forgejo encrypted, so keep it private, and copy /root/backup to another machine. On a new server, restore forgejo.env from the backup instead of creating a new key in step 3: with a new one, Forgejo cannot read what it encrypted, such as two-factor secrets.

Troubleshooting

Git cannot connect on port 2222. Check the ufw rule from step 1, and that docker compose ps in /home/forgejo/forgejo shows Forgejo running.

Everyone is logged out after an update or restart. The FORGEJO__session__PROVIDER=db line from step 4 is missing.

The runner stopped after systemctl --user reload. An older version of the service in step 8 had a reload that stops the runner. Use the service as it is there, and restart after changing the runner's settings.

A job waits and never starts. No runner has the name in its runs-on: line. Check it is docker or ubuntu-latest, and that the runner shows as Idle at /admin/actions/runners.

The checkout step fails with Failed to connect to git.example.com port 443. Job containers must have their own addresses on a Docker bridge network. Check that the rootless Docker daemon is running as runner, as in the Docker guide.

Run it on your own server

SSD RAID 1 · ECC DDR4 · 10 Gbit

VC-P Alloy

€8.99/mo

vCPU
2
Memory
8 GB
Storage
60 GB
Transfer
10 TB
Performance
SSD · RAID 1
  • Full root access
  • Native /64 IPv6
  • RAID-protected storage
  • Malmö, Sweden
  • Month to month, no lock-in
  • 7-day money-back guarantee
All guides