Wiki source code of How to set up a gitea docker instance
Version 3.1 by Alexandru Pentilescu on 2024/07/16 21:11
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{box cssClass="floatinginfobox" title="**Contents**"}}{{toc /}}{{/box}} | ||
2 | |||
3 | = Basic installation = | ||
4 | To setup a gitea server using docker, the following docker-compose.yml file shall be used: | ||
5 | |||
6 | {{code language="yaml"}} | ||
7 | version: '2' | ||
8 | |||
9 | networks: | ||
10 | gitea: | ||
11 | external: false | ||
12 | |||
13 | services: | ||
14 | web: | ||
15 | image: gitea/gitea:latest | ||
16 | environment: | ||
17 | - USER_UID=1002 | ||
18 | - USER_GID=1002 | ||
19 | volumes: | ||
20 | - ./data:/data | ||
21 | - /home/git/.ssh/:/data/git/.ssh | ||
22 | ports: | ||
23 | - "3000:3000" | ||
24 | - "2200:22" | ||
25 | depends_on: | ||
26 | - db | ||
27 | restart: always | ||
28 | networks: | ||
29 | - gitea | ||
30 | db: | ||
31 | image: mariadb | ||
32 | restart: always | ||
33 | environment: | ||
34 | - MYSQL_ROOT_PASSWORD=<redacted> | ||
35 | - MYSQL_DATABASE=gitea | ||
36 | - MYSQL_USER=gitea | ||
37 | - MYSQL_PASSWORD=<redacted> | ||
38 | volumes: | ||
39 | - ./db/:/var/lib/mysql | ||
40 | networks: | ||
41 | - gitea | ||
42 | {{/code}} | ||
43 | |||
44 | 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. | ||
45 | |||
46 | Before starting the docker services, please create the necessary resources first. | ||
47 | |||
48 | = Create the required local directories to store the data in = | ||
49 | |||
50 | Do a simple command to create the necessary directories: | ||
51 | |||
52 | {{code language="bash"}} | ||
53 | mkdir data db | ||
54 | {{/code}} | ||
55 | 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!!!** | ||
56 | |||
57 | = Create a separate git user to login into via SSH = | ||
58 | Creating a separate user, technically, is unnecessary, but it makes the configuration more conventional. | ||
59 | |||
60 | {{code language="bash"}} | ||
61 | useradd -m -u 1002 git | ||
62 | {{/code}} | ||
63 | |||
64 | 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**). | ||
65 | |||
66 | 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: | ||
67 | |||
68 | {{code language="bash"}} | ||
69 | chown git:git -R /home/git/.ssh/ | ||
70 | chmod 700 /home/git/.ssh/ | ||
71 | {{/code}} |