Wiki source code of How to set up a gitea docker instance
Version 5.1 by Alexandru Pentilescu on 2024/07/16 21:18
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{box cssClass="floatinginfobox" title="**Contents**"}} | ||
2 | {{toc /}} | ||
3 | {{/box}} | ||
4 | |||
5 | = Basic installation = | ||
6 | |||
7 | To setup a gitea server using docker, the following docker-compose.yml file shall be used: | ||
8 | |||
9 | {{code language="yaml"}} | ||
10 | version: '2' | ||
11 | |||
12 | networks: | ||
13 | gitea: | ||
14 | external: false | ||
15 | |||
16 | services: | ||
17 | web: | ||
18 | image: gitea/gitea:latest | ||
19 | environment: | ||
20 | - USER_UID=1002 | ||
21 | - USER_GID=1002 | ||
22 | volumes: | ||
23 | - ./data:/data | ||
24 | - /home/git/.ssh/:/data/git/.ssh | ||
25 | ports: | ||
26 | - "3000:3000" | ||
27 | - "2200:22" | ||
28 | depends_on: | ||
29 | - db | ||
30 | restart: always | ||
31 | networks: | ||
32 | - gitea | ||
33 | db: | ||
34 | image: mariadb | ||
35 | restart: always | ||
36 | environment: | ||
37 | - MYSQL_ROOT_PASSWORD=<redacted> | ||
38 | - MYSQL_DATABASE=gitea | ||
39 | - MYSQL_USER=gitea | ||
40 | - MYSQL_PASSWORD=<redacted> | ||
41 | volumes: | ||
42 | - ./db/:/var/lib/mysql | ||
43 | networks: | ||
44 | - gitea | ||
45 | {{/code}} | ||
46 | |||
47 | 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. | ||
48 | |||
49 | Before starting the docker services, please create the necessary resources first. | ||
50 | |||
51 | = Create the required local directories to store the data in = | ||
52 | |||
53 | Do a simple command to create the necessary directories: | ||
54 | |||
55 | {{code language="bash"}}mkdir data db{{/code}} | ||
56 | 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!!!** | ||
57 | |||
58 | = Create a separate git user to login into via SSH = | ||
59 | |||
60 | Creating a separate user, technically, is unnecessary, but it makes the configuration more conventional. | ||
61 | |||
62 | {{code language="bash"}} | ||
63 | useradd -m -u 1002 git | ||
64 | {{/code}} | ||
65 | |||
66 | 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**). | ||
67 | |||
68 | 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: | ||
69 | |||
70 | {{code language="bash"}} | ||
71 | chown git:git -R /home/git/.ssh/ | ||
72 | chmod 700 /home/git/.ssh/ | ||
73 | {{/code}} | ||
74 | |||
75 | Once all these steps are done, you can proceed to the next step. | ||
76 | |||
77 | = Spin up a container from the docker image = | ||
78 | |||
79 | {{code language="bash"}} | ||
80 | docker-compose up -d | ||
81 | {{/code}} | ||
82 | |||
83 | Had all the necessary steps been done properly, this should yield a fully functional container. If there are any errors encountered by this point, please fix them before proceeding. | ||
84 | |||
85 | = Set up a proper nginx endpoint for the docker service = | ||
86 | |||
87 | Deploy the following configuration to make the container accessible to the outside world: | ||
88 | |||
89 | {{code language="nginx"}} | ||
90 | server { | ||
91 | server_name git.transistor.one; | ||
92 | |||
93 | listen [::]:443 http2 ssl; # managed by Certbot | ||
94 | listen 443 http2 ssl; # managed by Certbot | ||
95 | # http2 on; | ||
96 | |||
97 | include /etc/nginx/snippets/ssl.conf; | ||
98 | |||
99 | location / { | ||
100 | proxy_pass http://localhost:3000; | ||
101 | } | ||
102 | } | ||
103 | {{/code}} | ||
104 | |||
105 | Once this is done, restart nginx: | ||
106 | |||
107 | {{code language="bash"}} | ||
108 | systemctl restart nginx | ||
109 | {{/code}} |