Gitea is a lightweight self-hosted Git service for private repositories, code review, issues, releases, and developer collaboration. Running it with Docker gives you a familiar web interface and SSH-based Git access while keeping source code, credentials, and project history on a server you control.

This guide covers a practical Docker Compose deployment, persistent storage, the initial setup wizard, HTTPS and SSH, database choices, backups, upgrades, and security decisions. It is useful for a homelab, a small team, or an internal development server that does not need the scale of a large hosted platform. If you are comparing self-hosted tools, our self-hosted Git server overview provides broader context.

What Gitea provides

Gitea gives a team a central place for Git repositories and the surrounding project workflow. Users can browse code, open issues, review pull requests, create releases, manage repository permissions, and clone over HTTPS or SSH. It can also integrate with webhooks, runners, package registries, and external identity systems.

The important distinction is that Gitea is a Git service, not a backup by itself. A repository on one server is still one failure domain. You need a separate backup plan for the Gitea data volume, database, configuration, and encryption secrets. Treat the instance as production software even if it runs in a home lab.

The official Gitea Docker documentation supports the docker.gitea.com/gitea image and provides Compose examples. The current reference uses a rootful image by default, while a separate rootless image is available. Rootful and rootless images are not compatible with each other, so choose one model and keep using it during upgrades.

Prepare the host

Use a Linux host with Docker Engine and Compose v2. Allocate persistent storage on an SSD if possible. Repositories themselves may be small, but large binaries, release assets, package artifacts, and CI logs can grow quickly.

Create a dedicated directory and a private environment file:

sudo mkdir -p /srv/gitea
sudo chown -R "$USER":"$USER" /srv/gitea
cd /srv/gitea
touch .env
chmod 600 .env

For a first installation using SQLite, the official documentation uses a single Gitea service and a host directory mounted at /data. The example below pins a stable release rather than using a floating development tag:

services:
  server:
    image: docker.gitea.com/gitea:28.2.0
    container_name: gitea
    environment:
      USER_UID: 1000
      USER_GID: 1000
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"

networks:
  gitea:
    external: false

The exact current release may be newer when you deploy. Check the official Docker installation documentation and update the tag deliberately. Gitea’s documentation notes that host-volume ownership must match the USER_UID and USER_GID values; incorrect permissions can prevent the container from starting.

Create docker-compose.yml, then inspect the rendered configuration before starting:

docker compose config
docker compose up -d
docker compose ps
docker compose logs --tail=100 server

The web interface should be available at http://server-ip:3000 for the initial wizard. Do not expose that plain HTTP endpoint to the public internet; use it only on a private network while configuring the instance.

Choose SQLite or PostgreSQL

SQLite is convenient for a small personal installation because it avoids another container. It can be a reasonable starting point for a few repositories and users, but PostgreSQL is the better long-term choice for a team-facing service, higher activity, or a migration plan that already uses a relational database.

The official documentation shows PostgreSQL connected through the Compose service name db on port 5432. A simplified pattern looks like this:

services:
  server:
    image: docker.gitea.com/gitea:28.2.0
    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: ${GITEA_DB_PASSWORD}
    volumes:
      - ./gitea:/data
    depends_on:
      - db

  db:
    image: docker.io/library/postgres:18
    environment:
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: ${GITEA_DB_PASSWORD}
      POSTGRES_DB: gitea
    volumes:
      - ./postgres:/var/lib/postgresql

Use a long password in .env and keep that file out of Git. The database should be reachable only over the private Compose network; do not publish port 5432 on the host unless you have a specific, firewall-protected administration need. Confirm the database image and storage path against the current Gitea documentation before a production deployment because image versions and supported defaults can change.

Configure the first administrator

Open the internal address or your temporary private proxy and complete the installation wizard. If you used PostgreSQL, the database hostname in the wizard is db, not localhost, because the application reaches the database over the Compose network.

Set the site title, base URL, repository root, log path, and SSH server settings carefully. The external URL must match the HTTPS address users will actually visit. A wrong base URL can produce broken clone links and callback URLs.

Create the first administrator with a unique password. Disable open registration unless you intentionally want anyone who finds the site to create an account. Invite users individually, or connect an identity provider after testing a local recovery administrator. SSO is convenient, but an external identity outage should not leave you without an emergency administrative path.

HTTPS and SSH access

Git clients need a stable public hostname. Put Gitea behind Caddy, Nginx, or another reverse proxy that terminates HTTPS. A simple Caddy entry for a host-bound web port might look like this:

git.example.com {
    reverse_proxy 127.0.0.1:3000
}

Do not use this example unchanged if the container is on another Docker network or if the proxy runs in a separate container. Ensure the proxy forwards normal HTTP requests and WebSocket connections, and verify that clone URLs show the correct HTTPS hostname.

Gitea’s integrated SSH service listens on container port 22. The example maps it to host port 222 so that the host’s own SSH daemon can continue using port 22. You can use a hostname and port in Gitea’s SSH settings, or put the service on a dedicated IP. Never confuse the host administration SSH service with Gitea’s Git SSH service when writing firewall rules.

A safer public layout usually permits only ports 80 and 443 to the reverse proxy, plus the selected Git SSH port if users need SSH cloning. Keep port 3000 bound to localhost or a private network. If the instance is only for a small trusted group, a VPN or private overlay such as Tailscale can avoid exposing the web interface publicly; see our Tailscale remote-access guide.

Repository permissions and integrations

Create organizations and teams before importing every repository. Give users the smallest role that lets them work, and use protected branches for important projects. Require pull requests for production code and restrict who can merge or change repository settings.

Webhooks, deploy keys, access tokens, package registries, and CI runners all extend the trust boundary. Use one credential per integration, give it only the required scopes, and rotate it when a team member leaves. Never paste cloud credentials into an issue or commit them to a repository. If a secret enters Git history, revoke it immediately; deleting the visible line is not enough.

For CI, keep runners isolated from the Gitea host where practical. A compromised build job can be more dangerous than a compromised web session because it may have access to source code, deployment credentials, and the Docker socket. Our Docker supply-chain security guide covers image and build precautions.

Backups that can restore repositories

A useful Gitea backup must include the database, the /data volume, the Compose file, the .env secrets, and any reverse-proxy or TLS recovery information. The data directory contains repositories, attachments, configuration, logs, and other application state. Backing up only PostgreSQL does not preserve Git repositories or uploaded release files.

For a PostgreSQL deployment, make a logical dump and archive the persistent directories:

mkdir -p backups

docker compose exec -T db pg_dump -U gitea -d gitea \
  | gzip > backups/gitea-$(date +%F).sql.gz

tar -czf backups/gitea-data-$(date +%F).tar.gz gitea
cp docker-compose.yml backups/

The service name and database path may differ in your Compose file, so confirm them with docker compose config before running the commands. For SQLite, include the database file inside /data and make a consistent copy when the service is stopped or use Gitea’s documented dump procedure.

Copy encrypted backups to a separate host. Our Restic backup guide describes versioned, encrypted off-site backups. Test a restore on a disposable server: create the database, restore the dump, restore /data, start the pinned image, and verify that a repository can be cloned. A backup that has never been restored is only a hope.

Protect Gitea’s generated secrets. The official documentation warns that changing SECRET_KEY can make encrypted data impossible to decrypt. Keep the recovery values in a secure password manager or encrypted backup, never in a public repository.

Updates and maintenance

Before an upgrade, read the Gitea release notes, record the current image tag, verify free disk space, and make a fresh backup. Gitea’s documented update pattern is to change the image version, pull the image, and recreate the container:

# Edit the image tag after reviewing the release notes
docker compose pull
docker compose up -d
docker compose ps
docker compose logs --tail=200 server

Pin a tested stable tag instead of blindly following a nightly image. The official documentation supports stable tags such as a full release tag, while nightly tags are intended for development or release-branch testing. Do not switch from the rootful image to the rootless image by changing only the image value; the two images are not compatible.

After each upgrade, test browser login, repository browsing, HTTPS cloning, SSH cloning, push, pull request creation, issue search, webhook delivery, and file uploads. Monitor logs and disk usage. Failed upgrades are easier to diagnose before users discover them during a production push.

FAQ: self-hosting Gitea

Is Gitea free to self-host?

The software can be self-hosted without a hosted subscription, but you provide the server, storage, backups, network, updates, and operational support.

Can I run Gitea with SQLite?

Yes. The official simple Docker setup can use SQLite when no separate database is configured. PostgreSQL is a stronger choice for a busier team service or a deployment that needs a conventional database backup workflow.

Which ports does Gitea use?

The reference Docker setup publishes web traffic on container port 3000 and integrated Git SSH on container port 22. Host ports can be changed, such as mapping SSH to 222 to avoid conflicting with the host’s SSH daemon.

Should port 3000 be public?

No. Put Gitea behind HTTPS and a reverse proxy, then bind the application port to localhost or a private network. Expose only the proxy and the intentionally selected Git SSH port.

Is the Gitea data directory enough for a backup?

It is essential, but the complete recovery set also includes the database when used, configuration, .env secrets, generated encryption keys, and proxy or TLS settings. Restore testing is required.

Gitea is a strong fit when you want Git hosting without surrendering repository control to a public SaaS platform. Use the official image and documentation, pin a stable release, secure the proxy and SSH path, protect the data volume, and practice restoration. The Docker command is the easy part; a private Git service becomes dependable only when its permissions, secrets, backups, and upgrade process are treated as seriously as the code it stores.