一谅阿、下載鏡像
官方版本是:gitlab/gitlab-ce:latest,為了提升速度我們這里使用阿里云的倉庫
$ docker pull registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest
二、運行GitLab容器
使用docker命令運行容器拍皮,注意修改hostname為自己喜歡的名字歹叮,-v部分掛載目錄要修改為自己的目錄。
端口映射這里使用的都是安全端口铆帽,如果大家的環(huán)境沒有端口限制或沖突可以使用與容器同端口咆耿,如:-p 443:443 -p 80:80 -p 22:22
1. 生成啟動文件 - 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. 運行start.sh 啟動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端口(如果主機端口使用的不是22端口)
修改文件:${GITLAB_DIR}/config/gitlab.rb 找到這一行:# gitlab_rails['gitlab_shell_ssh_port'] = 22 把22修改為你的宿主機端口(這里是2222)爹橱。然后將注釋去掉萨螺。
#等安裝完成,第一次有點慢
[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
- 重新啟動容器
[root@node01 config]# cd ..
[root@node01 gitlab]# sh start.sh
gitlab
gitlab
10b7d408b51981fcbd353ad4e10251746bda9061f68dac5a208df1a400a74a49
[root@node01 gitlab]# docker logs -f 10
三愧驱、GitLab試用
1. 打開首頁
地址:http://gitlab.wanfei.com:9080/
2. 設(shè)置管理員密碼
首先根據(jù)提示輸入管理員密碼慰技,這個密碼是管理員用戶的密碼。對應(yīng)的用戶名是root组砚,用于以管理員身份登錄Gitlab惹盼。
3. 創(chuàng)建賬號
設(shè)置好密碼后去注冊一個普通賬號
4. 創(chuàng)建項目
注冊成功后會跳到首頁,我們創(chuàng)建一個項目惫确,名字大家隨意
5. 添加ssh key
項目建好了手报,我們加一個ssh key,以后本地pull/push就簡單啦
然后拿到我們的sshkey 貼到框框里就行啦 怎么拿到呢改化?看下面:
- mac/linux
#先看看是不是已經(jīng)有啦掩蛤,如果有內(nèi)容就直接copy貼過去就行啦
$ cat ~/.ssh/id_rsa.pub
#如果上一步?jīng)]有這個文件 我們就創(chuàng)建一個,運行下面命令(郵箱改成自己的哦)陈肛,一路回車就好了
$ ssh-keygen -t rsa -C "youremail@example.com"
$ cat ~/.ssh/id_rsa.pub
- window電腦
如果已經(jīng)在本機生成了key在這里查看
- 如果沒有生成揍鸟,點擊下面生成
windows生成git ssh密鑰
6. 測試一下
點開我們剛創(chuàng)建的項目,復制ssh的地址
將idea的springcloud項目和gitlab上的項目關(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)代碼成功提交