Gitea Docker Setup
Self-hosted Git service with Docker Compose and SSL certificates for production deployment. Database is managed separately.
Quick Start
Local Development
- Copy the local environment configuration:
cp .env.local .env
- Update
.envwith your database connection details (ensure database is running):
nano .env
# Update DB_HOST, DB_USER, DB_PASSWORD
- Start Gitea:
docker-compose up -d
- Access Gitea at
http://localhost:3000
Production Deployment (repos.guschin.info)
- Copy the production environment configuration:
cp .env.production .env
- IMPORTANT: Edit
.envand update the database credentials:
nano .env
# Update DB_HOST, DB_USER, DB_PASSWORD with your external database connection
-
IMPORTANT: Ensure the MySQL database is running and accessible before starting Gitea
-
Install SSL certificates:
./install-certificates.sh
- Start Gitea:
docker-compose up -d
Configuration Files
docker-compose.yml- Docker Compose configuration for Gitea only.env- Active environment configuration (gitignored).env.local- Local development settings.env.production- Production environment settingsinstall-certificates.sh- SSL certificate installation for production
Environment Variables
Database Configuration (External)
DB_HOST- MySQL host (e.g., db-server.example.com:3306)DB_NAME- Database name (default: gitea)DB_USER- Database user (default: gitea)DB_PASSWORD- Database password (ensure it's secure!)
Gitea Configuration
GITEA_DOMAIN- Domain name (localhost or repos.guschin.info)GITEA_ROOT_URL- Full URL to Gitea instanceGITEA_HTTP_PORT- HTTP port mapping (default: 3000)GITEA_SSH_PORT- SSH port mapping (default: 2222 for local, 22 for production)
Common Commands
# Start Gitea
docker-compose up -d
# Stop Gitea
docker-compose down
# View logs
docker-compose logs -f gitea
# Restart Gitea
docker-compose restart gitea
# Check service status
docker-compose ps
Database Backup/Restore: Use commands on the external database server, not in docker-compose.
SSL Certificates
The install-certificates.sh script will:
- Install certbot if not present
- Obtain Let's Encrypt SSL certificates for repos.guschin.info
- Configure automatic certificate renewal
- Copy certificates to
./certsdirectory
Certificates are automatically renewed every 60 days.
Volumes
gitea-data- Gitea application data and repositories
Security Notes
- Always change default passwords in production
- Use strong passwords for database credentials
- Keep the
.envfile secure (it's gitignored by default) - Regularly update Docker images:
docker-compose pull && docker-compose up -d - Enable 2FA for Gitea admin accounts
Ports
- Local: HTTP on 3000, SSH on 2222
- Production: HTTP on 3000 (behind reverse proxy), SSH on 22
Troubleshooting
Database connection issues
Ensure the external database is running and accessible with the credentials in .env. Test the connection:
mysql -h ${DB_HOST} -u ${DB_USER} -p
Certificate issues
# Test certificate renewal
sudo certbot renew --dry-run
# Check certificate expiry
sudo certbot certificates
Permission issues
# Fix volume permissions
docker-compose down
sudo chown -R 1000:1000 ./volumes/gitea-data
docker-compose up -d
Description
Languages
Shell
100%