Setting Up Gitea on Ubuntu 20.04 with Docker: A Step by Step Guide

Posted on

Gitea is a lightweight, self-hosted Git service similar to GitHub, GitLab, and Bitbucket. This guide will walk you through the process of setting up Gitea on an Ubuntu server using Docker. By the end, you’ll have a fully functional Gitea instance ready for use.

Prerequisites

Before you start, ensure you have the following:

  • An Ubuntu server with a non-root user with sudo privileges.
  • Docker and Docker Compose installed on your server.
  • Basic knowledge of using the command line.

Step 1: Install Docker and Docker Compose

If you haven’t already, you’ll need to install Docker and Docker Compose. Follow these steps to get both installed:

  1. Update your package list:sudo apt update

       2. Install Docker:

sudo apt install docker.io

       3. Start and enable Docker:

sudo systemctl start docker
sudo systemctl enable docker

       4. Install Docker Compose:

sudo apt install docker-compose

Step 2: Create a Directory for Gitea

Create a directory to hold Gitea’s data and configuration files. This helps in managing Gitea’s data persistently.

mkdir -p ~/gitea/{data,config}

Step 3: Set Up Docker Compose

Create a docker-compose.yml file in the Gitea directory to define the Gitea service.

nano ~/gitea/docker-compose.yml

Paste the following content into the file:

version: “3”

services:
  server:
    image: gitea/gitea:latest
    environment:
      – USER_UID=1000
      – USER_GID=1000
    volumes:
      – ./data:/data
      – ./config:/etc/gitea
    ports:
      – “3000:3000”
      – “222:22”
    restart: always

Save and close the file.

Step 4: Launch Gitea

Navigate to the Gitea directory and launch the Gitea service using Docker Compose:

cd ~/gitea
sudo docker-compose up -d

This command will download the Gitea image and start the service in detached mode.

Step 5: Configure Gitea

Open your web browser and navigate to http://your_server_ip:3000 to access the Gitea web installer.

  1. Database Type: Select SQLite3 for simplicity.
  2. Path: Ensure the path is /data/gitea.db.
  3. Gitea Admin Account: Create your initial admin user account by filling in the required details.

Click on the “Install Gitea” button to complete the setup.

Step 6: Secure Gitea (Optional)

To secure your Gitea instance, consider the following steps:

  • Enable HTTPS: Use a reverse proxy like Nginx with a Let’s Encrypt certificate.
  • Configure SSH: Change the default SSH port to something other than 222 for added security.

Conclusion

You’ve successfully set up Gitea on Ubuntu using Docker. You now have a self-hosted Git service that you can use for your projects.

Leave a Reply

Your email address will not be published. Required fields are marked *