gitea的docker安装

Gitea是一个自己托管的 Git 服务程序。他和GitHub, BitbucketGitlab等比较类似。他是从Gogs 发展而来,Gitea的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务。

安装 docker-compose

Gitea在其Docker Hub组织内提供自动更新的Docker镜像。可以始终使用最新的稳定标签或使用其他服务来更新Docker镜像。

  1. 更新 apt 包索引并安装包以允许 apt 通过 HTTPS 使用存储库:
1
2
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
  1. 添加Docker的官方GPG密钥:
1
2
3
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
  1. 使用以下命令设置软件源:
1
2
3
4
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  1. 更新 apt 包索引:
1
sudo apt-get update
  1. 安装Docker EnginecontainerdDocker Compose:
1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

基本安装

最简单的设置只是创建一个卷和一个网络,然后将gitea/gitea:latest镜像作为服务启动。创建一个类似gitea的目录,并将以下内容粘贴到名为docker-compose.yml的文件中。请注意,该卷应由配置文件中指定的UID/GID的用户/组拥有。如果您不授予卷正确的权限,则容器可能无法启动。另请注意,标签 :latest 将安装当前的开发版本。对于稳定的发行版,您可以使用 :1 或指定某个发行版,例如 1.19.0-rc1。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
version: "3"

networks:
gitea:
external: false

services:
server:
image: gitea/gitea:1.19.0-rc1
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"

MySQL 数据库

要将GiteaMySQL数据库结合使用,请将这些更改应用于上面创建的docker-compose.yml文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
version: "3"

networks:
gitea:
external: false

services:
server:
image: gitea/gitea:1.19.0-rc1
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
+ - GITEA__database__DB_TYPE=mysql
+ - GITEA__database__HOST=db:3306
+ - GITEA__database__NAME=gitea
+ - GITEA__database__USER=gitea
+ - GITEA__database__PASSWD=gitea
restart: always
networks:
- gitea
volumes:
- ./gitea:/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=gitea
+ - MYSQL_USER=gitea
+ - MYSQL_PASSWORD=gitea
+ - MYSQL_DATABASE=gitea
+ networks:
+ - gitea
+ volumes:
+ - ./mysql:/var/lib/mysql

命名卷

要使用命名卷而不是主机卷,请在docker-compose.yml配置中定义并使用命名卷。此更改将自动创建所需的卷。您无需担心命名卷的权限;Docker将自动处理该问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
version: "3"

networks:
gitea:
external: false

+volumes:
+ gitea:
+ driver: local
+
services:
server:
image: gitea/gitea:1.19.0-rc1
container_name: gitea
restart: always
networks:
- gitea
volumes:
- - ./gitea:/data
+ - gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"

启动

要基于docker-compose启动此设置,请执行docker-compose up -d,以在后台启动Gitea。使用docker-compose ps将显示 Gitea 是否正确启动。可以使用docker-compose logs查看日志。

要关闭设置,请执行docker-compose down。这将停止并杀死容器。这些卷将仍然存在。

注意:如果在 http 上使用非 3000 端口,请更改app.ini以匹配LOCAL_ROOT_URL = http://localhost:3000/