Gitea with Docker Compose
Gitea’s own documentation ships a Docker Compose file with a PostgreSQL variant, and that file is the right starting point: two containers, two data folders, the web UI on port 3000 and Git over SSH on host port 222. Put a reverse proxy with TLS in front, finish the install wizard over an SSH tunnel, then set up backups before you push anything important. Pin the image to an exact release (28.4.0 as of 2 December 2026) so upgrades happen when you choose.
At a glance
| Item | What this guide uses |
|---|---|
| Gitea image | docker.gitea.com/gitea:28.4.0 (rootful), released 15 November 2026 |
| Database | docker.io/library/postgres:18, as in Gitea’s docs |
| Web port | 3000, bound to localhost; the reverse proxy serves 443 |
| Git over SSH | container port 22 mapped to host port 222 |
| TLS | Caddy (automatic certificates) or nginx with your own certificate |
| Backups | gitea dump inside the container, plus pg_dump, copied off the server |
| Upgrades | change the tag, docker compose pull, docker compose up -d |
If you are still deciding whether to run Gitea at all, read what Gitea is first, and browse the Git hosting hub for alternatives.
Before you start
You need a Linux server with Docker Engine and the Compose plugin, a domain name such as git.example.org pointing at it, and ports 80, 443 and 222 open. Any small VPS works for a personal or team forge; see choosing a VPS for self-hosting for what to look for. Gitea supports PostgreSQL 12 or newer, so the version 18 image in the docs is fine.
Pick an image: rootful or rootless
Gitea publishes two image flavors:
- Rootful (
docker.gitea.com/gitea:28.4.0) is the default in the docs. It runs a standalone OpenSSH server inside the container and keeps everything under/data. - Rootless (
docker.gitea.com/gitea:28.4.0-rootless) doesn’t need root privileges on the host but may have stricter UID/GID requirements. It must use Gitea’s built-in SSH server (container port 2222) and splits data into/var/lib/giteaand/etc/gitea.
The docs warn that the two images are not compatible: pick one and never switch by editing the image: line. This guide follows the rootful image because the main Docker page, the backup examples and most answers you will find assume it.
About tags: Gitea dropped the “1.” prefix with 28.0.0 in late September 2026. The docs still mention a :1 tag, but on Docker Hub that tag was last updated on 29 August 2026, the day 1.27.3 came out, so it no longer follows new releases. Use an exact tag like 28.4.0, or :28 if you accept automatic minor updates.
The Compose file
Create a directory, for example gitea, and save this as docker-compose.yml. It is the PostgreSQL example from Gitea’s Docker page with three changes: both passwords replaced with CHANGE_ME placeholders (use one long random value in both places), and the web port bound to 127.0.0.1 so only the reverse proxy on the same host can reach it.
networks:
gitea:
external: false
services:
server:
image: docker.gitea.com/gitea:28.4.0
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=db:5432
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=CHANGE_ME
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "127.0.0.1:3000:3000"
- "222:22"
depends_on:
- db
db:
image: docker.io/library/postgres:18
restart: always
environment:
- POSTGRES_USER=gitea
- POSTGRES_PASSWORD=CHANGE_ME
- POSTGRES_DB=gitea
networks:
- gitea
volumes:
- ./postgres:/var/lib/postgresql
Points worth knowing:
- Localhost binding matters. Docker’s Compose reference warns that a port published without a host IP binds to all interfaces and bypasses host firewall rules. Without
127.0.0.1:, port 3000 would be open to the internet even with a firewall in place. - Ownership. The
./giteafolder must be owned by the UID/GID inUSER_UIDandUSER_GID(1000 here), or the container may not start. - PostgreSQL is pinned on purpose. The docs note that PostgreSQL does not upgrade its data directory by itself; moving to a newer major version later needs
pg_upgradeor a dump and restore. The/var/lib/postgresqlmount path is correct for version 18. For 17 and older, the postgres image docs say to mount/var/lib/postgresql/datainstead, or data will not survive a container re-creation. - Settings as variables. Any
app.inisetting can be set with a variable namedGITEA__section_name__KEY_NAME. They are applied every time the container starts.
Start it with docker compose up -d, check it with docker compose ps, and read logs with docker compose logs.
First-run settings
Add the settings that depend on your domain to the environment: list of the server service before you run the wizard, so the wizard picks them up:
services:
server:
environment:
- GITEA__server__ROOT_URL=https://git.example.org/
- GITEA__server__SSH_DOMAIN=git.example.org
- GITEA__server__SSH_PORT=222
- GITEA__service__DISABLE_REGISTRATION=true
ROOT_URLis the public address. Behind a proxy it must match the HTTPS URL users visit. Gitea 28.0 ignores[server] DOMAINin favor ofROOT_URL, so set this one.SSH_DOMAINandSSH_PORTcontrol the SSH clone URLs.SSH_PORTis the port displayed to users, so 222 here, while OpenSSH inside the container keeps listening on 22.DISABLE_REGISTRATIONis alreadytrueby default since 28.0. Setting it explicitly documents the choice.
Run docker compose up -d again to apply changes. Because port 3000 only listens on localhost, open the wizard through an SSH tunnel from your own computer:
ssh -L 3000:localhost:3000 user@git.example.org
Then browse to http://localhost:3000. Until the wizard is finished, anyone who can reach it can configure the instance, which is why it should not be on the open internet. In the wizard:
- Under Database Settings, choose PostgreSQL and use
dbas the host, as the docs instruct for this Compose setup. - Check Gitea Website URL (your
ROOT_URL) and SSH Server Port (222). - Fill in Administrator Account Settings. This step is optional in the wizard, but if you skip it, the first person to register becomes administrator. The wizard also refuses to disable self-registration without an admin account.
After installation the installation page should no longer be reachable. Confirm that ./gitea/gitea/conf/app.ini contains INSTALL_LOCK = true under [security], or add GITEA__security__INSTALL_LOCK=true to the environment to pin it. Also back up that file now: it holds SECRET_KEY, and the docs warn that encrypted data such as two-factor secrets cannot be decrypted if the key is lost.
SSH access
With the rootful image, users clone over ssh://git@git.example.org:222/owner/repo.git. Open TCP 222 in your firewall and leave the host’s own SSH server on 22.
You have two documented choices:
- Separate port (the default above). Simple and fully contained. The only cost is the
:222in clone URLs, which some users find awkward. - Separate IP address. If the host has two addresses, the docs show binding the host’s SSH server to one (
ListenAddressin/etc/ssh/sshd_config) and Gitea’s container to the other, for example"192.168.1.2:22:22", adjusting the other published ports the same way. Clone URLs then use plain port 22.
Older Gitea guides described an “SSH container passthrough” that shares host port 22 through a shim script on the host. The current Docker page no longer documents it, so it is not reproduced here. If port 222 bothers you, the separate-IP option is the documented route.
Reverse proxy and TLS
Gitea’s proxy guide asks for ROOT_URL set to the public HTTPS address, URIs passed through without decoding, the Host and X-Forwarded-Proto headers forwarded, a certificate with its full chain, and WebSocket upgrades allowed on /-/ws.
Caddy is the shortest route, because it obtains and renews certificates by itself and redirects HTTP to HTTPS. The Caddyfile block from Gitea’s docs:
git.example.org {
reverse_proxy localhost:3000
}
nginx needs the location block from Gitea’s docs inside a server block that already has your TLS certificate configured:
server {
...
location / {
client_max_body_size 512M;
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Raise client_max_body_size if you push large files, or uploads fail with “413 Request Entity Too Large”. Gitea can also terminate TLS itself with built-in ACME support, but in a container the docs warn the default certificate directory sits outside the /data volume, so every re-created container requests new certificates and can hit Let’s Encrypt’s weekly limit. A reverse proxy avoids that.
Keep the admin side locked down
The site administration pages are part of the same web app, so protect them through accounts and network exposure:
- Keep port 3000 on localhost and reach Gitea only through the proxy.
- Give admin accounts two-factor authentication. Setting
TWO_FACTOR_AUTHtoenforcedin[security]makes it mandatory for everyone. - For a private team forge, set
REQUIRE_SIGNIN_VIEWtotruein[service]so nothing is visible without logging in, or serve the whole instance only over a VPN. - Use a normal account for daily work and the admin account only for administration.
If you add CI, treat runners as code execution on your hardware; the Gitea Actions runner guide covers that setup.
Backups
Gitea stores data in three places: the PostgreSQL database, the repositories, and files under /data/gitea (config, attachments, avatars, LFS). The docs’ Docker example for gitea dump, filled in for this setup (user git, container gitea, temporary directory /tmp):
docker exec -u git -it -w /tmp $(docker ps -qf 'name=^gitea$') bash -c '/usr/local/bin/gitea dump -c /data/gitea/conf/app.ini'
The ZIP lands in /tmp inside the container, named like gitea-dump-1482906742.zip. Copy it out with docker cp, using the name from the output:
docker cp gitea:/tmp/gitea-dump-1482906742.zip .
The dump contains an SQL file, but Gitea’s docs say the native tools are more reliable for restores. Take a PostgreSQL dump as well; this is the docs’ pg_dump command run in the db service, with -T so Compose does not allocate a terminal and the output can be redirected:
docker compose exec -T db pg_dump -U gitea gitea > gitea-db.sql
Drop -it from the docker exec line when you run it from cron, since there is no terminal. The docs also say a fully consistent backup requires Gitea to be stopped, because the database and repositories change separately during pushes and migrations. A dump from a running container is fine for most small instances if you run it at a quiet hour; for a strict copy, run docker compose down, copy the gitea and postgres folders, then docker compose up -d.
Then move the files off the server, to another machine or object storage, and test a restore. Restoring is manual: the docs show moving the unpacked files back with mv, importing the SQL dump (with psql for PostgreSQL) and running gitea admin regenerate hooks, with path variants for the rootful and rootless images.
Updates
The docs’ upgrade steps are to edit the tag in docker-compose.yml, then run docker compose pull and docker compose up -d. Before you change the tag:
- Read the release notes and the breaking-changes list. Gitea 28.0.0, for example, made self-registration off by default, began ignoring
[server] DOMAIN, and added a 400-day default retention for Actions run history. - Take a backup as described above.
- Stay current. Gitea’s release policy says security fixes go only to the latest major release.
Leave the PostgreSQL major version alone during routine Gitea upgrades; moving from 18 to a later major version is a separate job with pg_upgrade or a dump and restore.
What differs for Forgejo
Forgejo, the community fork, documents an almost identical Compose layout, but several details differ:
- Image:
codeberg.org/forgejo/forgejo:17(v17.0.2 is current), withdata.forgejo.orgas a mirror. The17tag follows minor releases; moving to the next major version is a manual step. - Config variables: Forgejo’s Docker docs use
FORGEJO__[SECTION]__[KEY]. Its migration guide notes that some variables still carry aGITEAprefix for compatibility and recommends passing both prefixes where they apply. - Paths: the rootful image also uses
/data; the rootless image mounts at/var/lib/giteaand maps SSH as222:2222. - Database example: Forgejo’s examples pin
postgres:14mounted at/var/lib/postgresql/data. Keep the mount path that matches your PostgreSQL major version, as explained above. - Backups: the command is
forgejo dump. - Switching: an existing Gitea database can move to Forgejo transparently only from Gitea 1.22 or older. A 28.x install cannot just swap images.
The Gitea vs Forgejo comparison covers governance, licences and release cycles if you have not chosen yet.
Frequently asked questions
- Which Gitea image tag should I use in Docker Compose?
- Pin an exact release such as 28.4.0, the current release on 2 December 2026, and change it on purpose when you upgrade. Gitea dropped the 1. prefix with 28.0.0, so the old :1 tag stopped moving at the 1.27 line; use :28 if you want a floating major tag.
- Should I use the rootful or the rootless Gitea image?
- The rootful image is the default in Gitea's docs and runs OpenSSH inside the container. The rootless image does not need root on the host and uses Gitea's built-in SSH server, but it has a different volume layout and stricter UID/GID needs. Pick one at the start: the docs say the two are not compatible and you should not switch by changing the image line.
- Why does Gitea use port 222 for SSH in Docker?
- Port 22 on the host is usually taken by the host's own SSH server, so Gitea's docs map the container's port 22 to host port 222. Set SSH_PORT to 222 so clone URLs show the right port. The alternative in the docs is giving Gitea its own IP address on the host.
- Does gitea dump back up the PostgreSQL database?
- Yes, the dump includes an SQL file, but Gitea's docs say the native pg_dump tool may restore more reliably because the built-in dump has open issues. Take both: gitea dump for repositories, attachments and config, and pg_dump for the database.
- Can I use the same Compose file for Forgejo?
- Mostly, with changes. Forgejo uses the image codeberg.org/forgejo/forgejo, the FORGEJO__ prefix for configuration variables, and its own examples pin an older PostgreSQL with a different data path. An existing Gitea 1.23 or newer database cannot simply be pointed at a Forgejo image.
Sources, checked December 2, 2026
- Gitea docs: Installation with Docker
- Gitea docs: Installation with Docker (rootless)
- Gitea docs: Database preparation (supported PostgreSQL versions)
- Gitea docs: Reverse proxies
- Gitea docs: HTTPS setup
- Gitea docs: Configuration cheat sheet
- Gitea docs: Backup and restore
- Gitea docs: Command line (dump options)
- Gitea 28.4.0 English locale file (install wizard labels)
- Gitea releases on GitHub (28.4.0, 15 November 2026)
- Gitea blog: Gitea 28.0.0 is released
- Gitea release management document
- Docker Hub: gitea/gitea tags
- Docker Hub: postgres official image (PGDATA change in 18)
- Docker docs: Compose workload specification (ports)
- Docker docs: docker compose exec
- Docker docs: docker container cp
- Caddy docs: Automatic HTTPS
- OpenSSH ssh(1) manual (-L port forwarding)
- Forgejo docs: Installation with Docker
- Forgejo docs: Gitea migration (environment variable prefixes)
- Forgejo docs: Command line (forgejo dump)
- Forgejo releases