数据库:mysql

git服务器:gogs/gitea

https://docs.gitea.io/zh-cn

https://gogs.io/

docker部署gogs/gitea

创建数据卷目录

1
2
3
4
mkdir -p /var/mysql/data
mkdir -p /var/mysql/log
mkdir -p /var/gogs
mkdir -p /var/gitea

编写docker-compose.yaml

gogs/gitea初始化数据库时填写mysql的IP地址(172.18.0.2)

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
version: '3'
services:
# mysql service
mysql:
container_name: mysql
image: mysql:5.7
ports:
- "3306:3306"
environment:
TZ: 'Asia/Shanghai'
MYSQL_ROOT_PASSWORD: 123456 # 数据库密码
MYSQL_DATABASE: gogs # 数据库名称
MYSQL_USER: root
MYSQL_PASSWORD: 123456
volumes:
- /var/mysql/data:/var/lib/mysql
- /var/mysql/log:/var/log/mysql
restart: always
command: mysqld --lower_case_table_names=1 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
networks:
gogs-network:
ipv4_address: 172.18.0.2
# gogs service
gogs:
container_name: gogs
image: gogs/gogs:latest
ports:
- "10022:22"
- "10080:3000"
volumes:
- /var/gogs:/data
#links: 废弃
#external_links:
# - mysql
depends_on:
- "mysql"
restart: always
environment:
TZ: 'Asia/Shanghai'
networks:
gogs-network:
ipv4_address: 172.18.0.3
# gitea service
gitea:
container_name: gitea
image: gitea/gitea:latest
ports:
- "20022:22"
- "20080:3000"
volumes:
- /var/gitea:/data
#links: 废弃
#external_links:
# - mysql
depends_on:
- "mysql"
restart: always
environment:
TZ: 'Asia/Shanghai'
networks:
gogs-network:
ipv4_address: 172.18.0.4

networks:
gogs-network:
driver: "bridge"
ipam:
driver: default
config:
- subnet: 172.18.0.0/24
# gateway: 172.18.0.1 version3 不需要

启动容器sudo docker-compose up -d

gogs/gitea初始化

配置数据库,填写数据库访问账号密码及ip

1
2
3
4
# 创建gitea数据库
sudo docker exec -it mysql bash
mysql -u root -p # passwd:123456
mysql> create database gitea;

设置gogs/gitea账号密码

操作指令

1
2
3
4
5
6
7
8
9
10
11
sudo docker-compose stop
sudo docker rm gogs mysql gitea
# 删除gogs创建的网桥
sudo docker network rm gogs_gogs-network
sudo rm -rf /var/mysql/data /var/mysql/log /var/gogs/ /var/gitea/

# 查看docker网桥
sudo docker network ls

sudo mkdir -p /var/mysql/data /var/mysql/log /var/gogs/ /var/gitea/
sudo docker-compose up -d