Gitea Docker Setup

This repository contains a Docker Compose configuration for running Gitea with PostgreSQL.

Prerequisites

  • Docker and Docker Compose installed
  • Nginx installed on host (for reverse proxy)
  • Domain name configured to point to your server

Environment Variables

Create a .env file in the project root with the following variables:

POSTGRES_DB=gitea
POSTGRES_USER=gitea
POSTGRES_PASSWORD=your_secure_password
GITEA_DOMAIN=git.example.com

Quick Start

  1. Clone this repository and navigate to the directory
  2. Create the .env file with your configuration
  3. Start the services:
docker-compose up -d

Gitea will be accessible at http://127.0.0.1:3000 and SSH at port 222.

Nginx Configuration

The repository includes example Nginx configurations in the nginx.example/conf.d/ directory:

  • gitea.httponly.conf - HTTP-only configuration (use this first)
  • gitea.conf - HTTPS configuration with SSL (use after obtaining certificates)

Initial Setup (HTTP Only)

  1. Copy the HTTP-only configuration to your Nginx config directory:
sudo cp nginx.example/conf.d/gitea.httponly.conf /etc/nginx/conf.d/gitea.conf
  1. Update the configuration file with your domain name
  2. Test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx

Setting Up HTTPS with Let's Encrypt

  1. Install certbot:
sudo dnf install certbot python3-certbot-nginx
  1. Create webroot directory:
sudo mkdir -p /var/www/certbot
  1. Obtain SSL certificate:
sudo certbot certonly --webroot \
    -w /var/www/certbot \
    -d git.example.com \
    --email your-email@example.com \
    --agree-tos \
    --no-eff-email
  1. Switch to HTTPS configuration:
sudo cp nginx.example/conf.d/gitea.conf /etc/nginx/conf.d/gitea.conf
  1. Update the configuration with your domain and certificate paths
  2. Test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx

Services

Gitea Server

  • Image: docker.gitea.com/gitea:1.25.4
  • HTTP Port: 3000 (localhost only)
  • SSH Port: 222 (accessible externally)
  • Data Volume: ./gitea:/data

PostgreSQL Database

  • Image: postgres:14
  • Data Volume: ./postgres:/var/lib/postgresql/data

Data Persistence

Data is persisted in the following local directories:

  • ./gitea - Gitea application data
  • ./postgres - PostgreSQL database data

Make sure to back up these directories regularly.

Accessing Gitea

  • Web Interface: Access through your configured domain (e.g., https://git.example.com)
  • SSH: Use port 222 for Git operations over SSH
git clone ssh://git@git.example.com:222/username/repository.git

Updating

To update Gitea to a newer version:

  1. Edit docker-compose.yaml and change the image version
  2. Pull the new image and recreate the container:
docker-compose pull
docker-compose up -d

Troubleshooting

Check container logs:

docker-compose logs -f server
docker-compose logs -f db

Security Notes

  • The Gitea HTTP port (3000) is bound to 127.0.0.1 only, accessible via Nginx reverse proxy
  • SSH is accessible on port 222 (non-standard port for added security)
  • Change default database credentials in the .env file
Description
No description provided
Readme 30 KiB