docker-gogs git服务器实践
前言
- 在对git服务器gitlab和gogs之间还是选择了gogs,因为它简单够用,消耗资源少,对于使用者来说,最频繁的无非就是代码拉取推送,够用就行。
- gogs/gogs: Gogs is a painless self-hosted Git service. https://github.com/gogs/gogs
- gogs/gogs - Docker Hub https://hub.docker.com/r/gogs/gogs
上面dockerhub关于gogs的资料就是从github搬过来的,并没有对于docker的使用做说明,因此也不用去dockerhub上找资料了
如果要看有关docker版运行的信息,请查看 https://github.com/gogs/gogs/tree/master/docker
实践
运行
-
现在本地创建一个名为data的目录,用于挂载容器内的数据
-
以下是运行docker版gogs的命令
#!/bin/sh docker run -it -d \ -p 10022:22 \ -p 10080:3000 \ -v /etc/localtime:/etc/localtime:ro \ -v $PWD/data:/data \ --restart always \ --name gogs \ gogs/gogs
上面比官方多的就是加了时区,否则在中国经常会有时区的问题,同时加了自动重启的设置,注意数据卷一定要设置,否则数据丢失就凉凉了
-
上面运行成功后我们可以在刚刚创建的data目录看到如下结构
data |-- git | |-- gogs-repositories |-- ssh | |-- # ssh public/private keys for Gogs |-- gogs |-- conf |-- data |-- log
-
上面中conf文件夹即可进行自定义配置,现在文件夹是空的,在首次安装后会生成app.ini,如果有配置修改都可以通过修改app.ini然后重新启动容器即可生效
-
运行成功后访问 http://localhost:10080 即可进入到首次安装界面,在这里对数据库,账号等信息进行设置,设置时最好做下笔记,免得以后忘记
安装数据库
-
gogs使用的是外部的数据库,因此需要先创建数据库,创建数据库的脚本,这里以mysql为例
-
数据库创建的脚本在 https://github.com/gogs/gogs/blob/master/scripts/mysql.sql 下
SET GLOBAL innodb_file_per_table = ON, innodb_file_format = Barracuda, innodb_large_prefix = ON; DROP DATABASE IF EXISTS gogs; CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
-
在外部创建好数据库后就按要求填写数据库配置相关信息即可,比如端口用户密码等,最后在安装时gogs会连接到你配置的数据库并自动创建好表的
配置
-
关于docker版的设置,英文原版是这样说的
Application
Most of settings are obvious and easy to understand, but there are some settings can be confusing by running Gogs inside Docker:- Repository Root Path: keep it as default value /home/git/gogs-repositories because start.sh already made a symbolic link for you.
- Run User: keep it as default value git because build.sh already setup a user with name git.
- Domain: fill in with Docker container IP (e.g. 192.168.99.100). But if you want to access your Gogs instance from a different physical machine, please fill in with the hostname or IP address of the Docker host machine.
- SSH Port: Use the exposed port from Docker container. For example, your SSH server listens on 22 inside Docker, but you expose it by 10022:22, then use 10022 for this value. Builtin SSH server is not recommended inside Docker Container
- HTTP Port: Use port you want Gogs to listen on inside Docker container. For example, your Gogs listens on 3000 inside Docker, and you expose it by 10080:3000, but you still use 3000 for this value.
- Application URL: Use combination of Domain and exposed HTTP Port values (e.g. http://192.168.99.100:10080/).
-
解释一下,大概就是说,仓库根目录和运行系统用户保持默认值即可,不要去修改他们;域名就写物理主机的ip;ssh端口写docker暴露的端口,在这里即为10022;http端口还是设置为原来的3000,就是说即使你暴露了10080,还是写3000;应用地址就写域名填的ip和http暴露的端口,即10080
-
其他配置很简单,看名称应该都知道怎么做,如果有些配置后期需要修改也是有办法的,如果填写无误的话点击安装等一会儿基本就完成了
参考
Gogs: A painless self-hosted Git service
https://gogs.io/
gogs/docker at master · gogs/gogs
https://github.com/gogs/gogs/tree/master/docker