How to set up a gitea docker instance

Version 3.1 by Alexandru Pentilescu on 2024/07/16 21:11

Basic installation

To setup a gitea server using docker, the following docker-compose.yml file shall be used:

version: '2'

networks:
 gitea:
   external: false

services:
 web:
   image: gitea/gitea:latest
   environment:
      - USER_UID=1002
      - USER_GID=1002
   volumes:
      - ./data:/data
      - /home/git/.ssh/:/data/git/.ssh
   ports:
      - "3000:3000"
      - "2200:22"
   depends_on:
      - db
   restart: always
   networks:
      - gitea
 db:
   image: mariadb
   restart: always
   environment:
      - MYSQL_ROOT_PASSWORD=<redacted>
      - MYSQL_DATABASE=gitea
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=<redacted>
   volumes:
      - ./db/:/var/lib/mysql
   networks:
      - gitea

What the above docker-compose configuration will do is that it will, in essence, create two, always on, services, that will forever be restarted: a mariadb database server that will write all of its data to a local "db" directory, and another web service that will server as the main git server and the web server alongside it.

Before starting the docker services, please create the necessary resources first.

Create the required local directories to store the data in

Do a simple command to create the necessary directories:

mkdir data db
Backing up just these two directories should, in theory, be enough to allow for full restoration of all git repository resources into the future. WARNING: This has not been tested yet!!!

Create a separate git user to login into via SSH

Creating a separate user, technically, is unnecessary, but it makes the configuration more conventional.

useradd -m -u 1002 git

Assuming the 1002 UID is already assigned to a different user, feel free to use a different UID (be sure to update the yaml configuration with the proper user ID, then).

Once this configuration has been done, go ahead and generate an /home/git/.ssh/ directory for the user to have. Be sure to chown this specific directory to the git user as appropriate:

chown git:git -R /home/git/.ssh/
chmod 700 /home/git/.ssh/