Gogs 是 一個能夠簡單自建Git托管服務的開源項目,用 go 語言實現(xiàn)秉氧。
Gogs 官方地址
概況
- 掌握了如何運用Docker安裝啟動 Gogs
- 掌握了如何運用Docker安裝啟動 Mysql
- 掌握了如何使用Docker compose 命令整合 Gogs & Mysql 兩個容器
MySQL 鏡像的下載、啟動容器
- 從默認的倉庫拉取mysql鏡像:
docker pull mysql
- 查看本地有哪些鏡像:
docker images
- 運行mysql鏡像生成名字叫做mysql2的容器敦跌,映射主機端口是13306,root密碼是123456 :
docker run
- 查看本地創(chuàng)建了哪些容器
docker ps
- 交互方式進入mysql2容器的shell環(huán)境膏潮,創(chuàng)建一個數(shù)據(jù)庫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 的配置和使用
打開chrome 瀏覽器掌腰,輸入網(wǎng)址 :http://192.168.1.161:10080/
-
第一次訪問Gogs,瀏覽器進入安裝頁面张吉,如圖所示填寫字段:
編輯 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/目錄
- 查看數(shù)據(jù)庫的情況
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)