Docker安裝GitLab和使用教程

一、下載鏡像

官方版本是:gitlab/gitlab-ce:latest,為了提升速度我們這里使用阿里云的倉(cāng)庫(kù)

$ docker pull registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest

二、運(yùn)行GitLab容器

使用docker命令運(yùn)行容器,注意修改hostname為自己喜歡的名字,-v部分掛載目錄要修改為自己的目錄。
端口映射這里使用的都是安全端口,如果大家的環(huán)境沒(méi)有端口限制或沖突可以使用與容器同端口,如:-p 443:443 -p 80:80 -p 22:22
1. 生成啟動(dòng)文件 - start.sh

[root@node01 ~]$ mkdir -p i/apps/gitlab
[root@node01 ~]$ cd i/apps/gitlab/
$ cat <<EOF > start.sh
#!/bin/bash
HOST_NAME=gitlab.wanfei.com
GITLAB_DIR=`pwd`
docker stop gitlab
docker rm gitlab
docker run -d \\
    --hostname \${HOST_NAME} \\
    --restart always \\
    -p 9443:443 -p 9080:80 -p 2222:22 \\
    --name gitlab \\
    -v \${GITLAB_DIR}/config:/etc/gitlab \\
    -v \${GITLAB_DIR}/logs:/var/log/gitlab \\
    -v \${GITLAB_DIR}/data:/var/opt/gitlab \\
    registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest
EOF

2. 運(yùn)行start.sh 啟動(dòng)gitlab

[root@node01 gitlab]$ sh start.sh
Error response from daemon: No such container: gitlab
Error: No such container: gitlab
29ffb281227a5724810e2a248e362079e48a358fa32d6574f2a30d78fee2a45e
#查看日志
docker logs -f 29

3. 配置環(huán)境

  • 修改host文件,使域名可以正常解析

192.168.2.43 gitlab.wanfei.com

  • 修改ssh端口(如果主機(jī)端口使用的不是22端口)

修改文件:${GITLAB_DIR}/config/gitlab.rb 找到這一行:# gitlab_rails['gitlab_shell_ssh_port'] = 22 把22修改為你的宿主機(jī)端口(這里是2222)。然后將注釋去掉。

#等安裝完成,第一次有點(diǎn)慢
[root@node01 gitlab]# ls
config  data  logs  start.sh
[root@node01 gitlab]# cd config/
[root@node01 config]# ls
gitlab.rb            ssh_host_ecdsa_key      ssh_host_ed25519_key      ssh_host_rsa_key      trusted-certs
gitlab-secrets.json  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key.pub  ssh_host_rsa_key.pub
[root@node01 config]# vi gitlab.rb
#修改
# gitlab_rails['gitlab_shell_ssh_port'] = 22
gitlab_rails['gitlab_shell_ssh_port'] = 2222
  • 重新啟動(dòng)容器
[root@node01 config]# cd ..
[root@node01 gitlab]# sh start.sh
gitlab
gitlab
10b7d408b51981fcbd353ad4e10251746bda9061f68dac5a208df1a400a74a49
[root@node01 gitlab]# docker logs -f 10

三、GitLab試用

1. 打開(kāi)首頁(yè)
地址:http://gitlab.wanfei.com:9080/
2. 設(shè)置管理員密碼
首先根據(jù)提示輸入管理員密碼,這個(gè)密碼是管理員用戶的密碼。對(duì)應(yīng)的用戶名是root,用于以管理員身份登錄Gitlab。


3. 創(chuàng)建賬號(hào)
設(shè)置好密碼后去注冊(cè)一個(gè)普通賬號(hào)

4. 創(chuàng)建項(xiàng)目
注冊(cè)成功后會(huì)跳到首頁(yè),我們創(chuàng)建一個(gè)項(xiàng)目,名字大家隨意


5. 添加ssh key
項(xiàng)目建好了,我們加一個(gè)ssh key,以后本地pull/push就簡(jiǎn)單啦


然后拿到我們的sshkey 貼到框框里就行啦 怎么拿到呢?看下面:

  • mac/linux
#先看看是不是已經(jīng)有啦,如果有內(nèi)容就直接copy貼過(guò)去就行啦
$ cat ~/.ssh/id_rsa.pub

#如果上一步?jīng)]有這個(gè)文件 我們就創(chuàng)建一個(gè),運(yùn)行下面命令(郵箱改成自己的哦),一路回車就好了
$ ssh-keygen -t rsa -C "youremail@example.com"
$ cat ~/.ssh/id_rsa.pub
  • window電腦
  • 如果已經(jīng)在本機(jī)生成了key在這里查看



  • 如果沒(méi)有生成,點(diǎn)擊下面生成
    windows生成git ssh密鑰

6. 測(cè)試一下
點(diǎn)開(kāi)我們剛創(chuàng)建的項(xiàng)目,復(fù)制ssh的地址


將idea的springcloud項(xiàng)目和gitlab上的項(xiàng)目關(guān)聯(lián)并提交

idea Terminal操作

16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud
$ git init
Initialized empty Git repository in D:/javaProject/idea/springcloud/.git/

16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud (master)
$ git remote add origin ssh://git@gitlab.wanfei.com:2222/www19930327/springcloud.git

16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in mvnw.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in mvnw.cmd.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/main/java/com/wf/springcloud/SpringcloudApplication.java.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in src/test/java/com/wf/springcloud/SpringcloudApplicationTests.java.
The file will have its original line endings in your working directory

16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud (master)
$ git commit -m "Initial commit"
[master (root-commit) 042e7aa] Initial commit
 9 files changed, 570 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .mvn/wrapper/maven-wrapper.jar
 create mode 100644 .mvn/wrapper/maven-wrapper.properties
 create mode 100644 mvnw
 create mode 100644 mvnw.cmd
 create mode 100644 pom.xml
 create mode 100644 src/main/java/com/wf/springcloud/SpringcloudApplication.java
 create mode 100644 src/main/resources/application.properties
 create mode 100644 src/test/java/com/wf/springcloud/SpringcloudApplicationTests.java

16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud (master)
$ git push -u origin master
The authenticity of host '[gitlab.wanfei.com]:2222 ([192.168.2.43]:2222)' can't be established.
ECDSA key fingerprint is SHA256:94ZQT2TyYym+E4dUK+CSO6zW7PTYrOrwSGLTVDsjUrc.
Are you sure you want to continue connecting (yes/no)? yes
Please type 'yes' or 'no': yes
Warning: Permanently added '[gitlab.wanfei.com]:2222,[192.168.2.43]:2222' (ECDSA) to the list of known hosts.
Enumerating objects: 25, done.
Counting objects: 100% (25/25), done.
Delta compression using up to 8 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (25/25), 48.18 KiB | 3.71 MiB/s, done.
Total 25 (delta 0), reused 0 (delta 0)
To ssh://gitlab.wanfei.com:2222/www19930327/springcloud.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

然后查看gitlab發(fā)現(xiàn)代碼成功提交


四. 在阿里云服務(wù)器上裝了gitlab后發(fā)現(xiàn)服務(wù)器非??D

解決辦法1
上面不行用這個(gè)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請(qǐng)注明:轉(zhuǎn)載自IT人故事會(huì),謝謝!原文鏈接地址:『高級(jí)篇』docker之gitlab和je...
    IT人故事會(huì)閱讀 1,667評(píng)論 0 6
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,551評(píng)論 19 139
  • 前言 在應(yīng)用還處于單體架構(gòu)的時(shí)候,交付周期通常都以周、月為單位,在這種情況下項(xiàng)目的部署一般都是由開(kāi)發(fā)人員手動(dòng)將程序...
    Briseis閱讀 22,297評(píng)論 5 70
  • 類似Safari的加載進(jìn)度條,除了比HUD更加簡(jiǎn)潔,也有更好的用戶體驗(yàn)。HUD會(huì)讓用戶覺(jué)得等待的時(shí)間很長(zhǎng),因?yàn)橛脩?..
    kuai空調(diào)閱讀 8,377評(píng)論 22 82
  • 我19歲遇見(jiàn)他 愛(ài)了到現(xiàn)在是整整兩年 其實(shí)我覺(jué)得我愛(ài)的不夠真切 越來(lái)越多的平衡杠在我心里 現(xiàn)實(shí) 距離 時(shí)間 ...
    貓步旅途閱讀 207評(píng)論 0 2

友情鏈接更多精彩內(nèi)容