Post

Gitea

Self-hosted Git service with Docker and PostgreSQL.

Gitea

Introduction

Gitea is a lightweight, self-hosted Git service written in Go. This guide will walk you through setting up Gitea with Docker and PostgreSQL using docker-compose.

Setting Up Gitea with Docker

Create a Directory

1
mkdir gitea && cd gitea

Create docker-compose.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
services:
  server:
    image: docker.io/gitea/gitea:latest
    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=gitea
    restart: unless-stopped
    networks:
      - gitea
    volumes:
      - ./gitea/data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"
    depends_on:
      - db

  db:
    image: docker.io/library/postgres:14
    restart: unless-stopped
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=gitea
      - POSTGRES_DB=gitea
    networks:
      - gitea
    volumes:
      - ./postgres:/var/lib/postgresql/data

networks:
  gitea:
    external: false

Start Gitea

1
docker-compose up -d

Installation

After starting the Docker setup, open your browser and visit http://server-ip:3000 to complete the installation via the web UI.

Customization

Customization files should be placed in the gitea/data directory as described in the official documentation.

Modify app.ini:

1
nano ./gitea/data/conf/app.ini

Example:

1
2
[server]
DISABLE_REGISTRATION = true # Disables registration so only admins can create accounts.

Restart Gitea for changes to take effect:

1
docker restart gitea

Setting Up a Runner (Optional)

To enable CI/CD workflows using Gitea Actions, set up a runner:

1
2
3
4
5
docker run -e GITEA_INSTANCE_URL=https://gitea.example.com \
           -e GITEA_RUNNER_REGISTRATION_TOKEN=<your_token> \
           -v /var/run/docker.sock:/var/run/docker.sock \
           --name my_runner \
           gitea/act_runner:nightly

Verify the runner is registered:

1
docker logs my_runner

Conclusion

You now have a self-hosted Git service running with Gitea, PostgreSQL, and optional CI/CD support. Happy coding!

This post is licensed under CC BY 4.0 by the author.