Gogs (Go Git Service) is a lightweight, self-hosted Git server written in Go, designed to be fast, simple, and easy to run on modest hardware. This guide deploys Gogs with a PostgreSQL backend using Docker Compose, with Traefik handling automatic HTTPS and SSH exposed on port 2222. By the end, you'll have a Gogs instance ready for repositories at your domain.
Set Up the Directory Structure
1. Create the project directory structure:
$ mkdir -p ~/gogs/{data,db,letsencrypt}
$ cd ~/gogs
2. Create the environment file:
$ nano .env
POSTGRES_USER=gogs
POSTGRES_PASSWORD=STRONG_DB_PASSWORD
POSTGRES_DB=gogs
DOMAIN=gogs.example.com
LETSENCRYPT_EMAIL=admin@example.com
Deploy with Docker Compose
1. Add your user to the Docker group:
$ sudo usermod -aG docker $USER
$ newgrp docker
2. Create the Docker Compose manifest:
$ nano docker-compose.yml
services:
traefik:
image: traefik:latest
container_name: traefik
restart: unless-stopped
environment:
DOCKER_API_VERSION: "1.44"
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--certificatesresolvers.le.acme.httpchallenge=true"
- "--certificatesresolvers.le.acme.httpchallenge.entrypoint=web"
- "--certificatesresolvers.le.acme.email=${LETSENCRYPT_EMAIL}"
- "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./letsencrypt:/letsencrypt
db:
image: postgres:16-alpine
container_name: gogs-db
restart: unless-stopped
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- ./db:/var/lib/postgresql/data
gogs:
image: gogs/gogs:latest
container_name: gogs
restart: unless-stopped
depends_on:
- db
ports:
- "2222:22"
volumes:
- ./data:/data
labels:
- "traefik.enable=true"
- "traefik.http.routers.gogs.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.gogs.entrypoints=websecure"
- "traefik.http.routers.gogs.tls=true"
- "traefik.http.routers.gogs.tls.certresolver=le"
- "traefik.http.services.gogs.loadbalancer.server.port=3000"
3. Start the services:
$ docker compose up -d
4. Verify the services are running:
$ docker compose ps
Complete the Installation
Open https://gogs.example.com in a browser and fill in the install form:
-
Database Host:
db:5432 -
Database User / Password / Name: the values from
.env -
SSH Port:
2222 -
Application URL:
https://gogs.example.com/
Configure the administrator account and click Install Gogs.
Next Steps
Gogs is running and served securely over HTTPS. From here you can:
- Create organizations and repositories, and invite collaborators
- Push and clone via SSH on port 2222 or HTTPS on 443
- Configure SMTP for email notifications and webhooks for CI integrations
For the full guide with additional tips, visit the original article on Vultr Docs.
Top comments (0)