docker.recipes

Gitea

beginner

Lightweight, self-hosted Git service with a beautiful interface, built-in CI/CD, and painless setup.

Overview

Gitea is a lightweight, self-hosted Git service written in Go that provides a GitHub-like interface for managing Git repositories. Born from a fork of Gogs in 2016, Gitea focuses on being painless to install and run while offering comprehensive features including pull requests, issue tracking, wiki pages, and built-in CI/CD through Gitea Actions. Its minimal resource requirements and straightforward setup make it an ideal choice for teams wanting private Git hosting without the complexity of larger platforms. This deployment configuration creates a robust Git hosting environment using two containerized services: the Gitea application server and a dedicated PostgreSQL database for data persistence. The setup leverages PostgreSQL's reliability and performance for storing repository metadata, user accounts, issues, and configuration data, while the Gitea container handles the web interface, Git operations, and SSH access. The two services communicate over a dedicated Docker network, with Gitea configured to automatically connect to PostgreSQL on startup. This combination provides excellent performance and reliability for teams requiring private code repositories with enterprise-grade database backing. The stack is particularly valuable for development teams, DevOps engineers, and organizations seeking complete control over their source code management while maintaining GitHub-like functionality and user experience.

Key Features

  • GitHub-like web interface with repository browsing, file editing, and commit history visualization
  • Built-in CI/CD through Gitea Actions with GitHub Actions compatibility for existing workflows
  • Comprehensive issue tracking system with labels, milestones, and project boards for agile development
  • Pull request workflow with code review, inline comments, and merge conflict resolution
  • PostgreSQL backend providing ACID compliance and robust data integrity for all Git metadata
  • SSH Git access on port 222 alongside HTTPS for flexible repository cloning and pushing
  • Package registry support for Docker, npm, PyPI, and other package formats
  • Repository migration tools for importing from GitHub, GitLab, and other Git services

Common Use Cases

  • 1Private Git hosting for software development teams requiring code privacy and control
  • 2DevOps environments needing integrated CI/CD pipelines with GitHub Actions compatibility
  • 3Educational institutions providing Git services for programming courses and student projects
  • 4Open source project hosting for communities wanting self-managed infrastructure
  • 5Enterprise development teams migrating from cloud Git services to on-premises solutions
  • 6Homelab environments for personal project management and portfolio development
  • 7Compliance-sensitive organizations requiring air-gapped or geographically restricted code hosting

Prerequisites

  • Docker and Docker Compose installed on the host system
  • Minimum 768MB RAM available (256MB for PostgreSQL, 512MB for Gitea application)
  • Ports 3000 (HTTP) and 222 (SSH) available and not conflicting with existing services
  • DB_PASSWORD environment variable configured in .env file or system environment
  • Basic understanding of Git operations and repository management concepts
  • SSH client configured if using SSH-based Git operations on port 222

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 gitea:
3 image: gitea/gitea:latest
4 container_name: gitea
5 restart: unless-stopped
6 environment:
7 USER_UID: 1000
8 USER_GID: 1000
9 GITEA__database__DB_TYPE: postgres
10 GITEA__database__HOST: db:5432
11 GITEA__database__NAME: gitea
12 GITEA__database__USER: gitea
13 GITEA__database__PASSWD: ${DB_PASSWORD}
14 volumes:
15 - gitea_data:/data
16 ports:
17 - "3000:3000"
18 - "222:22"
19 depends_on:
20 - db
21
22 db:
23 image: postgres:15-alpine
24 container_name: gitea-db
25 environment:
26 POSTGRES_USER: gitea
27 POSTGRES_PASSWORD: ${DB_PASSWORD}
28 POSTGRES_DB: gitea
29 volumes:
30 - gitea_db:/var/lib/postgresql/data
31
32volumes:
33 gitea_data:
34 gitea_db:

.env Template

.env
1DB_PASSWORD=changeme

Usage Notes

  1. 1Docs: https://docs.gitea.io/
  2. 2Access at http://localhost:3000 - setup wizard on first visit
  3. 3SSH clone: git clone ssh://git@localhost:222/user/repo.git
  4. 4First registered user becomes admin
  5. 5Gitea Actions for built-in CI/CD (GitHub Actions compatible)
  6. 6Package registry, issue tracker, wiki included

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

gitea
gitea:
  image: gitea/gitea:latest
  container_name: gitea
  restart: unless-stopped
  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: ${DB_PASSWORD}
  volumes:
    - gitea_data:/data
  ports:
    - "3000:3000"
    - "222:22"
  depends_on:
    - db
db
db:
  image: postgres:15-alpine
  container_name: gitea-db
  environment:
    POSTGRES_USER: gitea
    POSTGRES_PASSWORD: ${DB_PASSWORD}
    POSTGRES_DB: gitea
  volumes:
    - gitea_db:/var/lib/postgresql/data

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 gitea:
5 image: gitea/gitea:latest
6 container_name: gitea
7 restart: unless-stopped
8 environment:
9 USER_UID: 1000
10 USER_GID: 1000
11 GITEA__database__DB_TYPE: postgres
12 GITEA__database__HOST: db:5432
13 GITEA__database__NAME: gitea
14 GITEA__database__USER: gitea
15 GITEA__database__PASSWD: ${DB_PASSWORD}
16 volumes:
17 - gitea_data:/data
18 ports:
19 - "3000:3000"
20 - "222:22"
21 depends_on:
22 - db
23
24 db:
25 image: postgres:15-alpine
26 container_name: gitea-db
27 environment:
28 POSTGRES_USER: gitea
29 POSTGRES_PASSWORD: ${DB_PASSWORD}
30 POSTGRES_DB: gitea
31 volumes:
32 - gitea_db:/var/lib/postgresql/data
33
34volumes:
35 gitea_data:
36 gitea_db:
37EOF
38
39# 2. Create the .env file
40cat > .env << 'EOF'
41DB_PASSWORD=changeme
42EOF
43
44# 3. Start the services
45docker compose up -d
46
47# 4. View logs
48docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/gitea/run | bash

Troubleshooting

  • Gitea shows database connection error: Verify DB_PASSWORD environment variable matches between gitea and db services, check that db container is running and healthy
  • SSH Git clone fails on port 222: Ensure port 222 is not blocked by firewall and SSH daemon inside Gitea container is running, verify SSH keys are properly configured in Gitea web interface
  • First user registration fails: Check that gitea_data volume has proper write permissions for UID/GID 1000, restart gitea container if database initialization is incomplete
  • Gitea Actions workflows not triggering: Verify Gitea Actions is enabled in site administration settings and runners are properly registered and online
  • PostgreSQL container fails to start: Check available disk space for gitea_db volume and ensure no other PostgreSQL instances are conflicting with container startup
  • Web interface returns 502 Bad Gateway: Confirm gitea container started successfully after database connection was established, check container logs for application startup errors

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space