Create your own open-source GitHub alternative Gitea by installing on a Docker container and accessing it outside using the internet or locally.
What is Gitea?
Gitea is version management software, it is a fork of Gogs a resource-saving github.com clone. With any of these two systems, you can build your very own GitHub on your own servers. The range of functions is comparable to Github, Gitlab, Bitbucket, and some other providers. Over the past few years, Git has practically established itself as the “standard” in the world of software development. In addition to Git, there are other systems such as SVN (Subversion), CVS, or Mercurial.
It offers a similar Github interface and in addition to source code management, Gitea comes with other functions such as creating tickets or wikis.
We can even host Gitea locally and as it requires only low resources and computing power; the application can therefore also be made available on a Raspberry Pi.
Here we learn how to install Gitea on Docker container to easily access its Graphical user interface from anywhere and to start hosting source code of projects.
Steps to set up open-source GitHub alternative Gitea on docker container machine…
Install Docker Machine
The first thing you should have on your respective system is the availability of the Docker Community or enterprise version. If you have that, then move to the next step otherwise, use the given links to first install it.
- How to install Docker CE on Rocky Linux/CentOS/AlmaLInux 8
- Setup Docker on Ubuntu 20.04
- For Windows 10, use the Desktop version of Docker
Download MySQL & Gitea Docker Image
Most of the online guides will instruct to use docker-compose to instantly start with Gitea. However, thinking about beginners we go with the standard way to pull images using the docker command and then for the database.
docker pull gitea/gitea:1
docker pull mariadb
Create Gitea Container
Let’s create and run a Gitea Docker container using a single command.
docker run --name gitea -p 3000:3000 -p 22:22 -v /data:/data -d gitea/gitea:1
In the above command:
--name is to define the name of the container, here we have given it Gitea
Syntax- –p host-port:conainer-port
-p 3000:3000 : We are Mapping docker
3000 port with host
-p 22:22 : mapping SSH port of Docker with the host. In case, host 22 port is not free you can use any other.
-v /data:/data – Creating a folder to store Gitea data.
-d gitea/gitea:1: -d means run service in the background where
gitea/gitea:1 is the Image name we have pulled for it.
Create a container for MariaDB Database
You can use MySQL, however, here we are using MariaDB which is a fork of it.
To make sure our MySQL database has a backup file, we will map its default data folder with one created on the host. This will ensure even after removing the container our database content wouldn’t get completely wiped out, in case we want to use it in the future.
Note: Change the password in the below command before running with what you want to set for your root MySQL user.
docker run --name mariadbh2s -p 3306:3306 -v /opt/mariadb/backup:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d mariadb
Create a Database for Gitea on Docker
Connect to the MariaDB container and create Database for the Gitea platform-
docker exec -it mariadbh2s /bin/bash
Type the following and enter the password you have set for your MariaDB root user
mysql -u root -p
Use the below commands one by one to create a database. Change the bold text as per your choice.
create database yourDB; CREATE USER 'youUSER'@'localhost' IDENTIFIED BY 'pass'; grant all privileges on yourDB.* to youUSER@localhost; flush privileges; exit;
Access Web Interface
On your localhost or remote PC, enter the IP address of the host where you have installed the docker along with port number 3000.
However, you may need to open the port in the host firewall, for that run
For Ubuntu host–
sudo ufw allow 3000
For CentOS host-
sudo firewall-cmd --zone=public --add-port=300/tcp --permanent
To find host IP address type-
Also, note down the IP address of MariaDB docker container, using this command-
Syntax– docker inspect container-name | grep IPAddress
docker inspect mariadbh2s | grep IPAddress
1. Access Server
Now, on your browser enter the IP address of the host along with 3000 port number like this -example:
You will have the Gitea GUI web Interface, click on the Sign-in button.
2. Select Database Type – MySQL
3. Replace localhost:3306 with your MariaDB docker IP address you find above. After that enter the Database details, we have created above for Gitea such as root password and Database name.
Note: If you don’t change the IP address you will get an error: The database settings are invalid: dial tcp 127.0.0.1:3306: connect: connection refused
4. Change Gitea running on Docker Base URL
By default, the base URL will use the localhost, however, as we are accessing it outside the docker using host IP-address or domain name, thus replace localhost with your host IP-address here as well.
5. Go to the end and set the Administrator account Setting, set username and password.
6. Finally, hit the Install button.
7. And you will have the GitHub alternative and its similar interface Gitea on your own local or cloud hosting server.