How to Install Gitea Self-hosted Git Service using Docker on Ubuntu 18.04

Gitea is a fork of Gogs, the easy to use self-hosted Git service. It is similar to GitHub, Bitbucket, and Gitlab. Gitea is lightweight code hosting solution written in Go, can run on minimal hardware requirements. It is a cross-platform application, can run anywhere Go can be compiled such as Windows, Linux, MacOS, ARM etc.

In this tutorial, I will show you step-by-step how to install and configure the lightweight Git service using Gitea. We will deploy the Gitea server using Docker and will be using the PostgreSQL database and Traefik Reverse proxy. For this guide, we will be using the latest Ubuntu 18.04 Server.


  • Ubuntu 18.04
  • Root privileges

What we will do?

  1. Install Docker-CE
  2. Install Docker Compose
  3. Deploy Gitea as Container using Docker
  4. Gitea Post-Installation
  5. Create First Repository
  6. Testing First Commit

Step 1 – Install Docker-CE

The first step we will do for this guide is to install the Docker community edition to the Ubuntu 18.04 server. We will install the Docker CE package from the official Docker repository.

Add the Docker and Docker repository by running commands below.

curl -fsSL | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \

Add Docker Ubuntu Repository

The ‘add-apt-repository’ command will automatically update the repository.

Now install the Docker CE package.

sudo apt policy docker-ce
sudo apt install docker-ce=18.06.1~ce~3-0~ubuntu

install the Docker CE package

When the installation is complete, start the docker service and enable it to launch everytime at system boot.

sudo systemctl start docker
sudo systemctl enable docker

Docker CE is up and running on the Ubuntu 18.04 server. Verify the installation by checking the docker version.

docker version

Check Docker version

or run the docker ‘hello-world’.

docker run hello-world

docker run hello-world

Step 2 – Install Docker Compose

Docker-Compose is a command line tool for defining and managing multi-container docker applications. It allows you to create a container as a service, great for your development, testing and staging environment.

Install Docker Compose by downloading the binary file and make it an executable.

sudo curl -L$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Now check the docker-compose command.

docker-compose version

Docker Compose is now installed.

Install Docker Compose

Step 3 – Deploy Gitea as Docker Container

In this step, we will create a new docker-compose script that contains all services configuration including PostgreSQL Database and Traefik reverse proxy. We will set up all deployment files on the directory named ‘deployment’.

Create Custom Docker Network

Before creating the deployment configuration, let’s create a new custom bridge network. It will be used for the external service traefik reverse proxy.

Check the list docker network.

docker network ls

Now create a new custom bridge network named ‘hakasenet’.

docker network create hakasenet

Check it again.

docker network ls

Now you will get ‘hakasenet’ network on the list.

Check docker network

Setup Deployment Directory and Files

Create a new directory named ‘deployment’ and the ‘docker-compose.yml’ script on it.

mkdir deployment; cd deployment
touch docker-compose.yml

Now create new directory ‘gitea’ and ‘postgres’ data volume.

mkdir -p gitea/ postgres/

Create a new file ‘acme.json’ and change the permission of the file. it will be used to store Letsencrypt data.

touch acme.json
chmod 600 acme.json

Now create the global traefik configuration ‘traefik.toml’ file.

touch traefik.toml

And below are files and directories we’ve for the Gitea installation using Docker.


Setup Deployment Directory and Files

Setup PostgreSQL Service

The database service PostgreSQL is the first service that we want to configure. The database service will run only on the internal docker network.

And we will be using the Postgres 9.6 image, using ‘gitea’ as database name, user, and password, and set up the postgres data volume.

Edit the ‘docker-compose.yml’ file using vim.

vim docker-compose.yml

Paste configurations below.

version: "3"

 external: true
 external: false

 image: postgres:9.6
 restart: always
 - POSTGRES_DB=gitea
 - "traefik.enable=false"
 - internal
 - ./postgres:/var/lib/postgresql/data

Save and exit.

Setup Traefik Reverse Proxy

Now we will configure the Traefik reverse proxy for our Gitea installation.

The traefik service will be running under HTTP and HTTPS default ports, running on the custom bridge network named ‘hakasenet’, and we will configure it to use the Letsencrypt certificates that will be defined on the ‘traefik.toml’ file.

Edit the compose script.

vim docker-compose.yml

Paste configurations under the db service configuration.

 image: traefik:latest
 command: --docker
 - 80:80
 - 443:443
 - "traefik.enable=true"
 - "traefik.backend=dashboard"
 - ""
 - "traefik.port=8080"
 - hakasenet
 - /var/run/docker.sock:/var/run/docker.sock
 - ./traefik.toml:/traefik.toml
 - ./acme.json:/acme.json
 container_name: traefik
 restart: always

Save and exit.

Now edit the ‘traefik.toml’ configuration file.

vim traefik.toml

And paste the following configuration.

#Traefik Global Configuration
debug = false
checkNewVersion = true
logLevel = "ERROR"

#Define the EntryPoint for HTTP and HTTPS
defaultEntryPoints = ["https","http"]

#Define the HTTP port 80 and
#HTTPS port 443 EntryPoint
#Enable automatically redirect HTTP to HTTPS
address = ":80"
entryPoint = "https"
address = ":443"

#Enable Traefik Dashboard on port 8080
#with basic authentication method
#hakase and password
 users = [

dashboard = true

#Enable retry sending a request if the network error

#Define Docker Backend Configuration
endpoint = "unix:///var/run/docker.sock"
domain = ""
watch = true
exposedbydefault = false

#Letsencrypt Registration
#Define the Letsencrypt ACME HTTP challenge
email = "[email protected]"
storage = "acme.json"
entryPoint = "https"
OnHostRule = true
 entryPoint = "http"

Save and exit.


  • Change the acme letsencrypt email with your valid email address.

Setup Gitea Service

Edit the ‘docker-compose.yml’ configuration file.

vim docker-compose.yml

Paste the gitea service configuration at the bottom of the line.

 image: gitea/gitea:latest
 - USER_UID=1000
 - USER_GID=1000
 restart: always
 - internal
 - ./gitea:/data
 - "3000"
 - "22"
 - "traefik.enabled=true"
 - "traefik.backend=gitea"
 - ""
 - ""
 - "traefik.port=3000"
 - internal
 - hakasenet
 - db
 - traefik

Save and exit.

The Gitea service will be running on the TCP port ‘3000’, using those two docker networks ‘internal’ and ‘hakasenet’, and will run under the traefik reverse proxy on domain ‘’.

Docker composes configuration for Gitea deployment has been completed.

Deploy All Services

Now deploy the stack using ‘docker-compose’ command below.

docker-compose up -d

The command will download all docker images needed and run services defined on the docker-compose script.

Deploy All Services

And when it’s complete, check available services on docker using ps option as below.

docker-compose ps

Now you will get the result as below.

docker-compose ps

The PostgreSQL database, Gitea, and traefik reverse proxy containers are now up and running. The database service is running on the default port ‘5432’, the gitea server is running on port ‘3000’, and the traefik proxy is running on HTTP and HTTPS ports, accessible from the outside network/internet.

If you want to check all logs from docker check, run command below.

docker-compose logs

docker-compose logs

Step 4 – Gitea Post-Installation

Open your web browser and type your Gitea URL installation. Mine is:

Now you will get the default Gitea page.

Gitea run with Docker

Add the installation path to the URL.

Now you will get the Gitea installation page.

Database configuration

Type the PostgreSQL database details, and use ‘db‘ as a host.

Gitea web installer

General Gitea Configuration

Change the ‘Site title’ with your own title, the ‘SSH Server Domain’ (without https) and ‘Gitea Base URL’ with your gitea server URL.

General Gitea Configuration

Admin Account Settings

On the admin settings, type the admin username, password, and email address.

Admin Account Settings

Now click ‘Install Gitea’ button.

And you will be redirected to the Gitea default user dashboard.

Gitea default user dashboard

Step 5 – Create First Repository in Gitea

On the user home page, click the ‘+’ button.

Now type details of the repository that you want to create.

Add Repository

and click the ‘Create Repository’ button.

The repository has been created.

The repository has been created

Step 6 – Testing First Commit

Back to your terminal shell, and set up the default git user and email.

Run git commands below.

git config --global "hakase"
git config --global "[email protected]"

Now clone the repository.

git clone

Go to the repository directory ‘myyrepo’ and edit the file.

cd myrepo/

make changes on the README file, then save and exit.

Now commit the repository.

git add .
git commit -m 'Edit the file by hakase-labs'

And push it to the server.

git push origin master

Type your username and password.

And following should be the result.

Test Git Commit

Check to the repository page and make sure you get the changes as below.

Gitea installed

The Gitea installation with Docker on Ubuntu 18.04 has been completed successfully.


نوشته های مشابه