3.2 KiB
3.2 KiB
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
- Clone this repository and navigate to the directory
- Create the
.envfile with your configuration - 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)
- 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
- Update the configuration file with your domain name
- Test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Setting Up HTTPS with Let's Encrypt
- Install certbot:
sudo dnf install certbot python3-certbot-nginx
- Create webroot directory:
sudo mkdir -p /var/www/certbot
- 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
- Switch to HTTPS configuration:
sudo cp nginx.example/conf.d/gitea.conf /etc/nginx/conf.d/gitea.conf
- Update the configuration with your domain and certificate paths
- 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:
- Edit
docker-compose.yamland change the image version - 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
.envfile