Gitea in WSL: Setting up a Docker container
Gitea is a self-hosted Git service that is lightweight and easy to install. This article will cover how to set up a Gitea container in Windows Subsystem for Linux (WSL) using Docker Compose, volumes, bind mounts, and empty host settings.
Prerequisites
Before starting, make sure you have the following installed:
- WSL
- Docker
- Docker Compose
Setting up the Gitea container
Create a new directory for the Gitea container and navigate to it:
mkdir gitea && cd gitea
Create a new file named docker-compose.yml and add the following content:
version: "3"
services:
server:
image: gitea/gitea:latest
container_name: gitea
mem_reservation: "1G"
mem_limit: "2G"
volumes:
- ./gitea:/data
- ./custom:/custom
ports:
- "3000:3000"
- "222:22"
restart: always
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA_CUSTOM=1
- GITEA_PATH=/data
- GITEA_WORK_DIR=/data
This configuration sets up a Gitea container with the following settings:
- The container uses the latest version of the Gitea image.
- The container is named
giteaand has a memory reservation of 1GB and a limit of 2GB. - Two volumes are mounted:
./gitea:/dataand./custom:/custom. - The container exposes ports 3000 and 222.
- The container will always restart if it stops.
- Environment variables are set for the user ID, group ID, and Gitea settings.
Running the Gitea container
To start the Gitea container, run the following command:
docker-compose up -d
This will start the container in detached mode.
Accessing the Gitea web interface
To access the Gitea web interface, open a web browser and navigate to http://localhost:3000.
Configuring the Gitea container
To configure the Gitea container, you will need to create a new file named gitea.toml in the ./gitea directory.
Here is an example gitea.toml configuration file:
[server]
DOMAIN = "gitea.local"
HTTP_PORT = 3000
ROOT_URL = "http://%(DOMAIN)s:%(HTTP_PORT)s/"
[database]
DB_TYPE = "sqlite3"
DB_PATH = "/data/gitea.db"
[service]
REGISTER_NAT_ADDRESS = "127.0.0.1:3000"
EXTERNAL_URL = "http://gitea.local:3000"
LFS_START_SERVER = true
[repository]
CUSTOM_PATH_TEMPLATE = "{path}/{custom}.git"
This configuration sets up the following settings:
- The domain for the Gitea instance is set to
gitea.local. - The HTTP port is set to 3000.
- The root URL is set to
http://gitea.local:3000. - The database type is set to SQLite3 and the database path is set to
/data/gitea.db. - The register NAT address is set to
127.0.0.1:3000. - The external URL is set to
http://gitea.local:3000. - LFS start server is set to true.
- The custom path template is set to
{path}/{custom}.git.
In this article, we covered how to set up a Gitea container in WSL using Docker Compose, volumes, bind mounts, and empty host settings. This allows for easy management and scaling of the Gitea instance, as well as easy backups and restores of the data.
References
Note: The above content is provided as-is, and is intended to be used as a reference for setting up a Gitea container in WSL using Docker Compose, volumes, bind mounts, and empty host settings. It is not intended to be a complete guide, and should be used in conjunction with the official Gitea and Docker documentation.