Installing Gitea with Docker

As a developer, you’re always looking for ways to streamline your workflow and improve collaboration. One popular tool that can help is Gitea, a user-friendly Git repository manager. In this post, we’ll show you how to install Gitea with Docker and configure it with a MySQL database.

Requiring Software

Before starting the installation process, make sure you have:

These two tools will help us create and manage our containers for Gitea and its dependencies.


Step 1: Creating a Directory for the Container

To start the installation, we need to create a directory where we’ll store the container files. You can do this using the following command:

mkdir -p /docker/gitea

This will create a new directory called /docker/gitea where our container files will be stored.


Step 2: Configuring the Docker Compose File

Next, we need to create a docker-compose.yml file that defines our services. This file should contain the following configuration:

version: "3"

networks:
    gitea:
        external: false

services:
    server:
        image: gitea/gitea:latest
        container_name: gitea
        environment:
            - USER_UID=1000
            - USER_GID=1000
            - GITEA__database__DB_TYPE=mysql
            - GITEA__database__HOST=db:3306
            - GITEA__database__NAME=[DatabaseName]
            - GITEA__database__USER=[Username]
            - GITEA__database__PASSWD=[Password]
        restart: always
        networks:
            - gitea
        volumes:
            - /docker/gitea/data:/data
            - /etc/timezone:/etc/timezone:ro
            - /etc/localtime:/etc/localtime:ro
        ports:
            - "3000:3000"
            - "222:22"
        depends_on:
            - db

    db:
        image: mysql:8
        restart: always
        environment:
            - MYSQL_ROOT_PASSWORD=[Password]
            - MYSQL_USER=[Username]
            - MYSQL_PASSWORD=[Password]
            - MYSQL_DATABASE=[DatabaseName]
        networks:
            - gitea
        volumes:
            - /docker/gitea/mysql:/var/lib/mysql

In this configuration, we’re defining two services: server and db. The server service uses the latest Gitea image and maps port 3000 from the container to port 3000 on our machine. It also mounts a volume at /data for storing data and a volume at /etc/timezone for setting the timezone.

The db service uses the official MySQL image and sets up a database with the specified name, username, password, and root password.


Step 3: Substituting Placeholder Values

Next, we need to substitute placeholder values into our configuration file. These placeholders are:

  • [DatabaseName]: the name of your database
  • [Username]: the username for the MySQL database
  • [Password]: the password for the MySQL database
  • [Password]: the root password for the MySQL database

Replace these placeholder values with your own database credentials.


Step 4: Starting the Containers

Finally, we can start our containers using the following command:

docker-compose up

This will launch both the Gitea and MySQL containers, and you’ll be able to access Gitea at http://localhost:3000.


Conclusion

With these steps, you’ve successfully installed Gitea with Docker and configured it with a MySQL database. This setup provides a convenient way to manage your Git repositories and collaborate with team members.

If you have any questions or need further assistance, don’t hesitate to contact us.