利用Gogs搭建个人Git服务

服务器: CentOS 7
容器: Docker 18
环境: MySQL 5.7 + Gogs:0.11.66

1.Docker容器内安装MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
docker pull mysql

docker pull registry.docker-cn.com/library/mysql:8.0.12

docker pull registry.docker-cn.com/library/mysql:5.7

docker images |grep mysql

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

docker run --name mymysql -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 6a834f03bd02

/*数据卷的挂载*/
docker run -i -t --name mymysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 563a026a1511
error: database is uninitialized and password option is not specified 
    You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

进入MySQL终端

教程

1
2
3
4
docker exec -it 63ca57bd6dc5 /bin/bash

mysql -h 127.0.0.1 -u root -p
mysql -h 192.168.1.105 -u root -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

查看已经创建的容器

1
docker ps -a

查看正在运行的容器

1
docker ps -s

docker stop mymysql
docker rm mymysql
docker rmi 6a834f03bd02

防火墙开启3306端口

1
2
3
4
5
6
7
firewall-cmd --query-port=3306/tcp

firewall-cmd --add-port=3306/tcp

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --query-port=3306/tcp
1
2
exit
clear

MySQL Workbench连接

连接配置

2.Docker容器内安装Gogs

https://blog.upx8.com/1660

https://github.com/gogs/gogs/tree/master/docker

# Pull image from Docker Hub.
$ docker pull gogs/gogs:0.11.66

# Create local directory for volume.
$ mkdir -p /var/gogs

# Use `docker run` for the first time.
$ docker run --name=mygogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs:0.11.66

# Use `docker start` if you have stopped it.
$ docker start gogs

$ mysql -u root -p
mysql> # (输入密码)
mysql> create user 'gogs'@'localhost' identified by '密码';
mysql> grant all privileges on gogs.* to 'gogs'@'localhost';
mysql> flush privileges;
mysql> exit;

然后访问 http://192.168.1.105:10080/

Bingo:

创建仓库

I Don't Want Your Money, I Want Aragaki Yui.