Ubuntu+docker+gitlab安裝和使用


以前自己寫的代碼都是在本地,因為都是自己一個人維護,現在交給團隊維護了,所以想着搭建一個gitlab

1,拉鏡像

安裝非常簡單

docker search gitlab  搜索鏡像

docker pull gitlab/gitlab-ce 拉取鏡像

docker images 查詢鏡像

2,創建本地映射文件

test-team-server:~$ mkdir gitlab
test-team-server:~$ cd gitlab/
test-team-server:~/gitlab$ mkdir config logs data

3,安裝

docker run --detach -p 8843:443 -p 8090:80 -p 2222:22 --name gitlab --restart always -v /home/dapeng/gitlab/config:/etc/gitlab -v /home/dapeng/gitlab/logs:/var/log/gitlab -v /home/dapeng/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce


docker ps -a | grep gitlab

docker logs -f gitlab

4,配置

訪問gitlab http://192.168.1.119:8090

(1)設置密碼,初始賬戶為root,設置密碼之后就可以登錄了

(2)重啟、啟動、停止、狀態

gitlab-ctl restart  // 重啟

gitlab-ctl stop      // 停止

gitlab-ctl start     // 啟動

gitlab-ctl status  //狀態

(3)修改hostname

gitlab項目默認是以容器id作為hostname,ssh訪問的時候會提示hostname找不到,所以我們需要修改一下配置文件

/home/dapeng/gitlab/config/gitlab.rb   主要修改以下幾個值

external_url 'http://192.168.1.119'     #修改為http訪問的外部映射的主機ip和port

gitlab_rails['gitlab_ssh_host'] = '192.168.1.119'    #修改為ssh訪問的外部映射的主機ip或者hostname

gitlab_rails['gitlab_shell_ssh_port'] = 2222    #ssh默認是22端口,改成映射到外部的2222端口

然后執行一下docker restart gitlab

這樣在項目中顯示的訪問gitlab倉庫的地址是

ssh://git@192.168.1.119:8090:2222/automation/apitest.git

http://192.168.1.119/automation/apitest.git

(4)下載git.exe 到本地windows

ssh-keygen -o -t rsa -b 4096 -C "xxxxxxxxx@xxxxx.com"   然后一直回車

  • 復制~/.ssh/id_rsa.pub內容, 

~表示用戶目錄,比如windows就是C:\Users\Administrator

Administrator@ERIC MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCrPgBRiWV7d6yRTdkLkP0ae+6P571uMDtxAL1x2fsNGWvmzFZTHUrHS49UJgPpaGu0ZtOv4X7bX4mmEHlmSXo5v6lZ5YC+oEAWXgg2c+ES9jf4llfOggCYEIrek//xF6OTOrZxpvzrTkAroiTdeRtivnFnIMgaNz3rO53ryH0M5L9vzWFKm7ufuKyqY/910X73+9pP9Rf1txWgY8cd3iVGSjooKPND0rY34sVm7JQ16llx49MjIKTX79e2V3p+wy6LOuSawwH9XtQrakj01aXmhQHKIRIqTn0M0FYtEitEQxuagBdzeyMF46rMWrk8k87FnJaPsIm/WNRMVimiL4UlSjp3iSg4p/+GebzdBr8S3oXT6lWglQBVXLEYHZgXRQXNhTCOoeOWEdW1wtKYPpGY+LtMkSEGbt0/v68Fj3oDXllVle3SjlI4i9KF86snfQPd3jDvBu7padvDmwtl3bLWKA38/DLe+cTUSHgymTTmfW6fDT5VpcAlKkyh6Dvcyb0hlUGdNVzasQ4nqtQtODpGhb5pfdtJlhZN2P0QlI7n0KAEPkuQUnpNMKf94fmUxiH6QQLOeVrWuZw4CW/B+bnYHoe85vySNhUI+H2qat5+3/p09AD+mxffKbSgmR6QWE9DXFTIGjtJ01dMFy699Qi8YOVsXwViOiu9Lab9ymxqLQ== hailiangyou@dingtalk.com

(4)網頁上配置ssh-key

http://192.168.1.119:8090/profile/keys

把上面cat出來的內容復制到gitlab頁面上

 

 5,拉取項目,git常規使用

1,創建一個文件夾作為倉庫repo   D盤下的repo文件夾

打開git bash, cd /d/repo

2,設置用戶名和郵箱

git config --global user.name "eric"

git config --global user.email "xxxx@xxx.com"

3,克隆項目,默認拉取的是master分支

git clone ssh://git@192.168.1.119:2222/automation/apitest.git

Administrator@ERIC MINGW64 /d/repo
$ git clone ssh://git@192.168.1.119:2222/automation/apitest.git
Cloning into 'apitest-framework'...
The authenticity of host '[192.168.1.119]:2222 ([192.168.1.119]:2222)' can't be established.
ECDSA key fingerprint is SHA256:IoMGBM4jlCN20ynwVKKrvwUFb8pKP5BjfZy5QG0/A2c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.119]:2222' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

4,git使用

在本地創建一個待push的測試文件,test.md 

touch test,md

git status  #可以看到紅色提示該分支有需要更新的文檔 test.md

 

 git add test.md  #添加文件到待上傳的緩沖區里

git commit -m "test push test.md"   #提交並解釋

 

 

git push origin master  #提交到倉庫主分支

 

 然后就可以在gitlab網頁上看到剛剛提交的文件

關於更詳細的git使用教程,可以查看https://www.runoob.com/git/git-tutorial.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM