Gogs-Docker&OS Installation

Gogs 是 一个能够简单自建Git托管服务的开源项目,用 go 语言实现。
Gogs 官方地址

timg (3).jpg

概况

  • 掌握了如何运用Docker安装启动 Gogs
  • 掌握了如何运用Docker安装启动 Mysql
  • 掌握了如何使用Docker compose 命令整合 Gogs & Mysql 两个容器

MySQL 镜像的下载、启动容器

  1. 从默认的仓库拉取mysql镜像:docker pull mysql
  2. 查看本地有哪些镜像:docker images
  3. 运行mysql镜像生成名字叫做mysql2的容器,映射主机端口是13306,root密码是123456 : docker run
  4. 查看本地创建了哪些容器 docker ps
  5. 交互方式进入mysql2容器的shell环境,创建一个数据库testdb docker exec
[root@localhost ~]# docker pull mysql
[root@localhost ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
mysql                                   latest              eda6a4884645        2 days ago          383.4 MB
hello-world                             latest              c54a2cc56cbb        3 months ago        1.848 kB
index.tenxcloud.com/huangqg/wordpress   latest              88bc02275ad7        12 months ago       485.5 MB
[root@localhost ~]# docker run -d -p 13306:3306  --name mysql2 -v /opt/mydata/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:latest
01ff7db79a2bba578f4cef7024cd1e02bfec1084478e7835a79aeed317278b03
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
01ff7db79a2b        mysql:latest        "docker-entrypoint.sh"   29 seconds ago      Up 27 seconds       0.0.0.0:13306->3306/tcp   mysql2
[root@localhost ~]# docker exec -it mysql2 /bin/bash
root@01ff7db79a2b:/# mysql --version
mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrapper
root@01ff7db79a2b:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> create database testdb;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)

主机(Win10中文版)访问虚拟机MySQL的 Docker 容器 mysql2
看到了 testdb 的存在

D:\>mysql -h 192.168.1.161 -P 13306 -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> create database testdb;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)

Gogs 镜像的下载、启动容器

[Gogs 镜像地址] (https://hub.docker.com/r/gogs/gogs/)

[root@localhost ~]# docker pull gogs/gogs
Using default tag: latest
latest: Pulling from gogs/gogs
6c123565ed5e: Pull complete
b42f29d13b9c: Pull complete
01150f5f4ffe: Pull complete
be1365fee626: Pull complete
6ccc52766b77: Pull complete
cb0e4cd5b47d: Pull complete
Digest: sha256:f206e8bcc77c8577fe1c4a94e59fe3a3a0ddb8e0f8f4fa6cf4a88d241c645d20
Status: Downloaded newer image for gogs/gogs:latest
[root@localhost ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
mysql                                   latest              eda6a4884645        4 days ago          383.4 MB
gogs/gogs                               latest              d28f8296a1e9        4 weeks ago         89.22 MB
hello-world                             latest              c54a2cc56cbb        3 months ago        1.848 kB
index.tenxcloud.com/huangqg/wordpress   latest              88bc02275ad7        12 months ago       485.5 MB
[root@localhost ~]# docker run -d --name=mygogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs 
8d9da372bd4373532623cf875300ef21c0b166f78f2fd73cdf9b733cc747f647
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
8d9da372bd43        gogs/gogs           "docker/start.sh /bin"   7 seconds ago       Up 6 seconds        0.0.0.0:10022->22/tcp, 0.0.0.0:10080->3000/tcp   mygogs
01ff7db79a2b        mysql:latest        "docker-entrypoint.sh"   27 hours ago        Up 42 minutes       0.0.0.0:13306->3306/tcp                          mysql2

Gogs 的配置和使用

  1. 打开chrome 浏览器,输入网址 :http://192.168.1.161:10080/

  2. 第一次访问Gogs,浏览器进入安装页面,如图所示填写字段:

    [图片上传失败...(image-f6d30a-1522666749864)]

    [图片上传失败...(image-e64808-1522666749864)]

  3. 编辑 Gogs 配置文件(vi /var/gogs/gogs/conf/app.ini
    修改 ROOT_URL = http://192.168.1.161:10080/

......
[server]
DOMAIN       = 192.168.1.161
HTTP_PORT    = 3000
ROOT_URL     = http://192.168.1.161:10080/
DISABLE_SSH  = false
SSH_PORT     = 10022
OFFLINE_MODE = false
......

问题:为什么可以修改 Host 的 /var/gogs/ 目录的文件,就可以改变容器里的配置文件?
答案:因为启动容器的时候,我们使用 -v /var/gogs:/data 把 Host 里的目录 /var/gogs 挂载到容器的/data/目录

  1. 查看数据库的情况
C:\Users\andy>mysql -h 192.168.1.161 -P 13306 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| gogs               |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
6 rows in set (0.06 sec)

mysql> use gogs
Database changed
mysql> show tables;
+----------------+
| Tables_in_gogs |
+----------------+
| access         |
| access_token   |
| action         |
| attachment     |
| collaboration  |
| comment        |
| deploy_key     |
| email_address  |
| follow         |
| hook_task      |
| issue          |
| issue_label    |
| issue_user     |
| label          |
| login_source   |
| milestone      |
| mirror         |
| notice         |
| org_user       |
| public_key     |
| pull_request   |
| release        |
| repository     |
| star           |
| team           |
| team_repo      |
| team_user      |
| update_task    |
| upload         |
| user           |
| version        |
| watch          |
| webhook        |
+----------------+
33 rows in set (0.00 sec)

一款极易搭建的自助 Git 服务。

环境

centos7:golang+mysqldb+git

安装配置环境

yum install mysql-community-server  go  git  -y

配置防火墙 selinux

安装配置数据库

这个mysql不允许简单的密码,所以第三条语句我未执行,后面安装时候直接用root作为数据库的用户。gogs推荐使用InnoDB引擎。创建库时候选择utf8.

systemctl start mysqld ;systemctl enable mysqld
//开启数据库服务

cat /var/log/mysqld.log | grep password
//获得mysql root密码

mysql_secure_installation
//初始化数据库 使用上一步获得密码

mysqld -u root -p
//登录mysql

SET GLOBAL storage_engine = ‘InnoDB‘;
CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON gogs.* TO ‘root’@‘localhostIDENTIFIED BY ‘itadmin’;
FLUSH PRIVILEGES;
QUIT;
//SQL语句

安装配置gogs

wget https://dl.gogs.io/0.11.4/linux_amd64.tar.gz
//下载软件包

tar  -zxf  linux_amd64.tar.gz;   mv gogs    /gogs
//解压

useradd git
chown -R  git:git   /gogs
mkdir /gogs-repositories
chown  -R  git:git   /gogs-repositories
//添加git用户 

su git
/gogs/gogs web &
//启动gogs

最下方配置选项建议点一点做详细配置,如果添加内置SSH避开系统上的22端口,管理员账号不允许admin 避开吧

image
image
至此安装结束

gogs下载地址

gogs配置文件手册

gogs文档手册

分类: gogs

u=3010770648,3949130722&fm=27&gp=0.jpg

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,692评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,482评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,995评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,223评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,245评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,208评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,091评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,929评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,346评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,570评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,739评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,437评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,037评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,677评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,833评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,760评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,647评论 2 354

推荐阅读更多精彩内容

  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,530评论 15 147
  • 转载自 http://blog.opskumu.com/docker.html 一、Docker 简介 Docke...
    极客圈阅读 10,499评论 0 120
  • Gogs 是 一个能够简单自建Git托管服务的开源项目,用 go 语言实现。Gogs 官方地址 概况 掌握了如何运...
    andy0898阅读 11,949评论 3 6
  • 故事一开始 一眼就看见了你 在陌生的操场上 你瘦削的侧脸和黑色T恤都发着光 美好的让人嫉妒 震惊的是 在教室后排看...
    冬树白鸥阅读 172评论 0 1
  • 鸟声打在树梢 一刻一阵欢喜吗 可别比阳光还灿烂
    李译阅读 339评论 2 7