
Gogs (Go Git Service) is a lightweight, self-hosted Git server designed to be fast, simple, and easy to deploy. It provides repository hosting, SSH/HTTPS support, issues, user management, and a clean web interface similar to Gitea or GitHub.
This article demonstrates how to deploy Gogs on Ubuntu 24.04 using Docker Compose and secure it behind a Traefik reverse proxy for automatic HTTPS.
Before you begin:
gogs.example.com, pointing to your server’s public IP.Set up directories for persistent Gogs data, database files, and Let's Encrypt certificates.
Create the folder structure.
data – Stores Gogs repositories, configs, SSH keysdb – PostgreSQL dataletsencrypt – Stores Traefik ACME certificatesMove into the project folder.
Create a .env file to store variables used in Docker Compose.
Add the following:
Replace:
STRONG_DB_PASSWORD with a secure passwordgogs.example.com with your domainadmin@example.com with your emailSave and close the file.
This section deploys Gogs using Docker Compose, Traefik for HTTPS, and PostgreSQL for storage.
Add your user account to the docker user group.
Apply new group membership.
Create and edit a Docker Compose manifest file.
Add the following contents.
Save and close the file.
This Docker Compose file deploys Gogs behind Traefik, enabling secure HTTPS access using Let’s Encrypt. Each service has a specific purpose:
traefik service
traefik-public network via labels.le ACME resolver with the email address from ${LETSENCRYPT_EMAIL} to request and renew SSL certificates from Let’s Encrypt../letsencrypt directory (mounted as /letsencrypt)./var/run/docker.sock) in read-only mode.db service (PostgreSQL)
${POSTGRES_USER}, ${POSTGRES_PASSWORD}, and ${POSTGRES_DB} (defined in your .env file) to configure the database../db directory on the host.gogs service
Runs the Gogs Git server application.
Depends on the db service to ensure the database is started first.
Runs as UID/GID 1000 inside the container (USER_UID and USER_GID) so file ownership lines up with your host user.
Stores repositories, SSH keys, and configuration under the ./data directory on the host.
Exposes port 22 from the container as port 2222 on the host for SSH Git access (ssh -p 2222).
Registers itself with Traefik using labels:
traefik.http.routers.gogs.rule tells Traefik to route requests for your domain to this container.websecure entrypoint (HTTPS) with TLS enabled.le certificate resolver to obtain certificates from Let’s Encrypt.Start All Services
Check that containers are running.
You should see gogs, gogs-db, and traefik listed as "Up".
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
Open your browser and visit your Gogs domain https://gogs.example.com. The Install Steps For First-time Run page loads.
Fill in required fields:
db:5432.envhttps://gogs.example.com/2222, or the host port value you set in the gogs.ports field.Scroll down to the Optional Settings section, and expand the Admin Account Settings.
Set the credentials for an administrator account
Click Install Gogs. After installation, Gogs dashboard opens. You now have a fully functional Gogs instance secured with HTTPS.
By following this article, you successfully deployed Gogs on Ubuntu 24.04 using Docker Compose and secured it with Traefik. Your Git service now supports HTTPS, repository hosting, SSH access, and user management. For more information, visit the official Gogs documentation.
0 Comments
Be the first to comment and share your perspective with the community.