Centos下的纯命令记录Docker学习(11)- 使用Doc
数据库安装
拉取postgresql数据库镜像且运行容器
[root@localhost ~]# docker pull postgres:9.4
[root@localhost data]# docker run --name gogs_pg -v /data/gogs/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=123456 -p 5432:5432 -d postgres:9.4
2a748fb74403a6cdb6d9bc3db44659a75daedb3e1771d6df0d359130f0041cb0
拉取gogs镜像并启动容器
1: 拉取镜像
[root@localhost ~]# docker search gogs
不要搞错镜像名称协成 [root@localhost ~]# docker pull gogs
[root@localhost ~]# docker pull gogs/gogs
2:查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 7d64f4d8e205 21 minutes ago 41.1MB
flaskmimi v1 684f5068c203 33 minutes ago 930MB
<none> <none> 89ff27e65c45 38 minutes ago 89.9MB
gogs/gogs latest e74419abc2b9 3 days ago 96.1MB
dockerflask latest 476011fc293b 5 days ago 924MB
flask_web_stj latest 1410b6bc6d9d 2 weeks ago 913MB
newmynginx latest cd903b9a327f 2 weeks ago 146MB
python 3.6-alpine 876b6a885b74 2 weeks ago 40.2MB
python 3.6 1297140c6dd2 2 weeks ago 874MB
python 3.7-alpine 6b73b71fd64e 2 weeks ago 41.1MB
tomcat latest 891fcd9c5b3a 5 weeks ago 647MB
nginx latest f35646e83998 5 weeks ago 133MB
redis 4.0.14 191c4017dcdd 6 months ago 89.3MB
postgres 9.4 ed5a45034282 9 months ago 251MB
hell02 latest bf756fb1ae65 10 months ago 13.3kB
centos centos7.1.1503 e1430271e2f9 20 months ago 212MB
python 3.6.5-alpine 5be6d36f77ee 2 years ago 89.9MB
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
[root@localhost ~]#
3: 启动容器并挂载数据到外部
docker run --name=gogs -p 10022:22 -p 10080:3000 -v /data/gogs/data:/data gogs/gogs
后台启动
docker run --name=gogs -p 10022:22 -p 10080:3000 -v /data/gogs/data:/data -d gogs/gogs
4: 重新的启动后台启动容器
[root@localhost ~]# docker start gogs
gogs
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19e9c50af663 gogs/gogs "/app/gogs/docker/st…" About a minute ago Up 6 seconds 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->3000/tcp gogs
f16826df749b 7d64f4d8e205 "/bin/sh -c 'apk add…" 30 minutes ago Up 30 minutes mystifying_hopper
[root@localhost ~]#
配置对应的数据
(1)查看当前运行的容器
[root@localhost data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a046e8e2783 gogs/gogs "/app/gogs/docker/st…" 10 seconds ago Up 9 seconds 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->3000/tcp gogs
2a748fb74403 postgres:9.4 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp gogs_pg
[root@localhost data]# ^C
[root@localhost data]#
(2)通过浏览器访问地址配置运行信息
http://192.168.219.130:10080/install
(3)数据库配置运行信息
image.png修正数据库主机
image.png
再修正
image.png image.png
image.png
使用工具先新建数据库
image.png
再继续安装
(4)应用基本信息配置
image.png(5)其他信息配置
image.png(6)立即安装(注意需要先新建数据库名称,再执行立即安装)
image.pngPS:密码设置为
zyx308711822账号:
zyx308711822620PW
使用操作篇
(1)新建组织
image.png错误提示
image.png image.png image.png
(2) 团队操作
image.png(3) 新建仓库
image.png(4) http方式获取仓库
image.png从命令行创建一个新的仓库
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://192.168.219.130:10080/mycode/test.git
git push -u origin master
从命令行推送已经创建的仓库
git remote add origin http://192.168.219.130:10080/mycode/test.git
git push -u origin master
(5) windows下git服务端安装和下载安装git客户端用户本地进行相关的仓库的操作
服务端git
下载地址:https://git-scm.com/downloads
tortoisegit
下载地址:
https://tortoisegit.org/download/
Sourcetree
下载地址:https://www.sourcetreeapp.com/
使用介绍:https://www.cnblogs.com/tian-xie/p/6264104.html
或者直接使用腾讯管家安装
git安装:(参考:https://blog.csdn.net/qq_41868500/article/details/85778784)
1.双击安装程序“Gitxxxxx.exe”:
2.点击“Next”,显示如下:
image.png
3.点击“Next”,显示如下
image.png
选择说明:
说明:
(1)图标组件(Addition icons) : 选择是否创建桌面快捷方式。
(2)桌面浏览(Windows Explorer integration) : 浏览源码的方法,使用bash 或者 使用Git GUI工具。
(3)关联配置文件 : 是否关联 git 配置文件, 该配置文件主要显示文本编辑器的样式。
(4)关联shell脚本文件 : 是否关联Bash命令行执行的脚本文件。
(5)使用TrueType编码 : 在命令行中是否使用TruthType编码, 该编码是微软和苹果公司制定的通用编码。
image.png
4.点击“Next”,显示如下
image.png
5.点击“Next”,显示截图如下:
image.png
设置环境变量
选择使用什么样的命令行工具,一般情况下我们默认使用Git Bash即可:
(1)Git自带:使用Git自带的Git Bash命令行工具。
(2)系统自带CMD:使用Windows系统的命令行工具。
(3)二者都有:上面二者同时配置,但是注意,这样会将windows中的find.exe 和 sort.exe工具覆盖,如果不懂这些尽量不要选择。
6.选择之后,点击“Next”,显示截图如下:
image.png
7.选择之后,继续点击“Next”,显示如下:
image.png
选择提交的时候换行格式
(1)检查出windows格式转换为unix格式:将windows格式的换行转为unix格式的换行再进行提交。
(2)检查出原来格式转为unix格式:不管什么格式的,一律转为unix格式的换行再进行提交。
(3)不进行格式转换 : 不进行转换,检查出什么,就提交什么。
8.选择之后,点击“Next”,显示截图如下:
9.选择之后,点击“Next”,显示截图如下:
image.png
image.png
image.png
image.png
10.安装完成之后,显示截图如下: 、
image.png
客户端安装:
参考:https://blog.csdn.net/qq_39505065/article/details/89404148?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control image.png
image.png image.png
image.png
image.png
image.png image.png
image.png
image.png
查看右键菜单信息:
image.png
(6) 然后进行命令的操作
参考:https://www.jianshu.com/p/86c385682ac8
在windos下某个目录下创建一个文件夹
image.png
进入到mycode里面进行git初始化
image.png image.png从命令行创建一个新的仓库
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin http://192.168.219.130:10080/mycode/test.git
git push -u origin master
image.png
输入错误的密码和用户之后的解决方案
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode (master)
$ git push -u origin master
libpng warning: iCCP: cHRM chunk does not match sRGB
fatal: Authentication failed for 'http://192.168.219.130:10080/mycode/test.git/'
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode (master)
$ git remote add origin http://192.168.219.130:10080/mycode/test.git
fatal: remote origin already exists.
image.png
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode (master)
$ git push -u origin master
libpng warning: iCCP: cHRM chunk does not match sRGB
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 205 bytes | 205.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.219.130:10080/mycode/test.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode (master)
查看提交的日志:
image.png
查看仓库情况
image.png
image.png
从命令行推送已经创建的仓库
git remote add origin http://192.168.219.130:10080/mycode/test.git
git push -u origin master
(7) 通过HTTP方式获取仓库
image.png image.png image.png使用命令操作提交最新的操作:
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ touch xiaozhong.text
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ nano xiaozhong.text
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ git
git.exe git-lfs.exe
git-askyesno.exe git-receive-pack.exe
git-credential-helper-selector.exe git-upload-archive.exe
gitdll.dll git-upload-pack.exe
gitdll32.dll GitWCRev.exe
git-flow GitWCRevCOM.exe
gitk
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ git add .
warning: LF will be replaced by CRLF in xiaozhong.text.
The file will have its original line endings in your working directory
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ git commit -m '新的一次的提交测试'
[master 4cbd634] 鏂扮殑涓€娆$殑鎻愪氦娴嬭瘯
1 file changed, 1 insertion(+)
create mode 100644 xiaozhong.text
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 316 bytes | 316.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.219.130:10080/mycode/test.git
495c450..4cbd634 master -> master
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/mycode2/test (master)
$
查看最新的仓库情况:
image.png
(7) 通过SSH获取仓库(有问题暂未解决)
首先检查本地.shh下是否存在公钥信息
- 第一步: 进入到我们的服务器上面进行,在当前根目录下可以执行执行完ssh-keygen之后
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:9nAaAXX/81fFMSRRcCyfhPHsXC4gsC/n94UFi2vYqec root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| ..o . =O* |
| . + . o=+o|
| o . o =o=|
| o . +o*o|
| S + . =o+|
| . X o o *.|
| . + * . +|
| +.. ..|
| .oE . |
+----[SHA256]-----+
[root@localhost ~]# ^C
[root@localhost ~]#
image.png
执行完ssh-keygen之后
执行完ssh-keygen之后会在,用户目录下的.ssh文件下,生成一个id_rsa文件和id_rsa.pub文件。
id_rsa文件是私钥,要保存好,放在本地,私钥可以生产公钥,反之不行。
id_rsa.pub文件是公钥,可以用于发送到其他服务器,或者git上。
- 第二步: 查看我们的文件是公钥且复制id_rsa.pub公钥内容
[root@localhost ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGuBF8GDFfosUtcyc90RTfKtk0uyqHpsVBiHjTxS/0YjgOY4+ouaZ2szwWHmLvk68cyWgRC2xsy4A/Y7BuUXcz0FjWGaNjIg1ajSBqhL7xSg6cstQ/+buGFg4XntyY87ouSEstqdb4gjDf/BC8Ef71G53EKQJ2oUWAXr1sdC/eVEWSR9sExZBzYY6KKVJCIceS81wMxQResxqna03Oh5pQQZChWHniK+Pxmzs4Q7P7OMr4h0L0Jct6xZU383TyRuf9T/tpMn4QA47chTw+7/rhK7xG51eNpdb8F0qQErpdpIPuj5w9MgtmqLCe8JMsDmC0w1DMMsiinL4IBUptR0VN root@localhost.localdomain
[root@localhost ~]#
image.png
image.png
- 第三步: 复制ssh连接仓库需要的参数
image.png指定的目录下:
image.png
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/sshmycode
$ git clone ssh://git@192.168.219.130:10022/mycode/test.git
Cloning into 'test'...
The authenticity of host '[192.168.219.130]:10022 ([192.168.219.130]:10022)' can't be established.
ECDSA key fingerprint is SHA256:dGdauklR4xJocchH0fU6Im93ODe7JN2OcOJzEnc6BM4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added '[192.168.219.130]:10022' (ECDSA) to the list of known hosts.
git@192.168.219.130: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
mayn@DESKTOP-16CKEN1 MINGW64 /d/code/gitpro/sshmycode
$
提示异常:
Warning: Permanently added '[192.168.219.130]:10022' (ECDSA) to the list of known hosts.
git@192.168.219.130: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
提示异常2:
image.png
Gogs 设置Git钩子实现项目自动部署测试
image.pngpre-receive:接收前
update:接收时
post-receive接收后 (如果push代码后实现更新部署可执行这个会用到post-receive)
编辑测试更新后 执行某个脚本,在我们的某个文件创建一个目录
PS:因为我们的使用了数据卷的,所以一般是需要给与外置的GOGS的数据卷的赋予一定的权限
编写脚本信息:
#!/bin/bash
mkdir -p /data/ceshigogspull
image.png
PULL前:查看本地的目录文件情况:
[root@localhost .ssh]# cd /data/
[root@localhost data]# ls
backup composetest dockerflask html web_statistics wwwroot2
bak dockerceshilink gogs jiao www
ceshi dockerflask houtaiquandian.tar QQpro wwwroot
[root@localhost data]#
image.png
PULL后:查看本地的目录文件情况:
image.png
查看内容
image.png
image.png
说没我们的钩子已经能够执行了!!!