Self-Host Gitea with Docker Compose: Git Service Setup
This tutorial was written with AI assistance from the project's official documentation. Verification status is stated at the end of the article. What Gitea does and what it needs Gitea is a single-binary Git service written in Go. It bundles repository hosting, pull requests, issue tracking, wikis, a package registry, and a GitHub Actions-compatible CI runner into one process. The official image…
Gitea is a self-hosted Git service written in Go that bundles repository hosting, pull requests, issue tracking, wikis, a package registry, and a CI runner into a single process. The official image is `gitea/gitea` and it exposes ports 3000 for HTTP and 22 for SSH-based Git operations. Gitea stores data in a SQL database (SQLite by default) and the `GITEA_WORK_DIR` directory. For production, it is recommended to use PostgreSQL and a volume for `/data` to prevent data loss on container restarts.
The prerequisites for setting up Gitea include a Linux VPS with Docker Engine 24+ and the Compose plugin. The port 80 and 443 should be free for the reverse proxy, and the Git hostname (e.g. `git.example.com`) should be pointed at the server via a DNS A or AAAA record. Ports 80 and 443 are used for the web proxy, while port 2222 is reserved for Git SSH. Two volumes are needed: `gitea_data` for repositories, LFS, attachments, and `app.ini`, and `gitea_db` for the database.
To set up Gitea, create a project directory, create a `.env` file, and fill in the placeholders with strong random values. Next, create a `compose.yml` file that runs Gitea and PostgreSQL, wires the secrets from `.env`, and sets up volume mappings and port bindings. After running `docker compose up -d`, wait for the server to start and confirm it is healthy using `docker compose ps`. Register the admin account immediately after the container is up to gain full access to the site.
To secure the setup, enable HTTPS with a reverse proxy like Caddy or Nginx, and complete the first-run hardening checklist. This includes disabling user registration, verifying the `ROOT_URL` matches the public HTTPS URL, and ensuring SSH clone works. Lastly, enable two-factor authentication (2FA) for the admin account under Settings → Security. Updating Gitea is as simple as bumping the image tag in the `compose.yml` file and running `docker compose pull` followed by `docker compose up -d`.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.