门门雨 2019-06-28
使用docker+gogs方式搭建自己的私有代码服务器
Gogs官网文档地址
docker pull mysql
创建物理目录,用于存储mysql数据
mkdir /opt/docker/mysql/data
mkdie /opt/docker/mysql/conf
在配置文件目录下新增文件: docker.cnf, mysql.cnf, mysqldump.cnf
[mysqld] skip-host-cache skip-name-resolve
[mysql] default-character-set = utf8 [mysql_safe] default-character-set = utf8 [client] default-character-set = utf8 [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql #log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 修改mysql默认字符集 init_connect = 'SET NAMES utf8' character-set-server = utf8 collation-server = utf8_unicode_ci
[mysqldump] quick quote-names max_allowed_packet = 16M
启动mysql docker run -d --name gogs-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -v /opt/docker/mysql/data:/var/lib/mysql -v /opt/docker/mysql/conf:/etc/mysql/conf.d mysql:latest
参数说明:
镜像操作
docker start gogs-mysql
docker rm gogs-mysql
docker exec -it gogs-mysql /bin/bash
docker pull gogs/gogs
mkdir /opt/docker/gogs
启动:docker run -d --name=mygogs -p 10022:22 -p 10080:3000 -v /opt/docker/gogs:/data gogs/gogs
参数说明:
镜像操作
docker start mygogs
docker rm mygogs
docker exec -it mygogs /bin/bash
http://192.168.3.61:10080/
/opt/docker/gogs/gogs/log
docker ps -a
docker logs --tail=200 gogs-mysql
docker logs -f gogs-mysql
浏览器访问 http://192.168.3.61:10080即可操作
设置nginx配置,保存信息,重启nginx服务
server { listen 80; server_name 域名信息; #方向代理 gogs访问 location / { proxy_pass http://127.0.0.1:10080/; proxy_redirect default; } #access_log /var/log/nginx/gogs/access.log main; #error_log /var/log/nginx/gogs/error.log; }
修改gogs配置
[server] DOMAIN = sudo docker exec -it mysql /bin/bash HTTP_PORT = 3000 ROOT_URL = 上一步更改的域名信息 DISABLE_SSH = false SSH_PORT = 10022 START_SSH_SERVER = false OFFLINE_MODE = false
重启gogs,即可访问