Docker安装GitLab和使用教程

一、下载镜像

官方版本是:gitlab/gitlab-ce:latest,为了提升速度我们这里使用阿里云的仓库

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

二、运行GitLab容器

使用docker命令运行容器,注意修改hostname为自己喜欢的名字,-v部分挂载目录要修改为自己的目录。
端口映射这里使用的都是安全端口,如果大家的环境没有端口限制或冲突可以使用与容器同端口,如:-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. 配置环境

  • 修改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. 设置管理员密码
首先根据提示输入管理员密码,这个密码是管理员用户的密码。对应的用户名是root,用于以管理员身份登录Gitlab。


3. 创建账号
设置好密码后去注册一个普通账号

4. 创建项目
注册成功后会跳到首页,我们创建一个项目,名字大家随意


5. 添加ssh key
项目建好了,我们加一个ssh key,以后本地pull/push就简单啦


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

  • mac/linux
#先看看是不是已经有啦,如果有内容就直接copy贴过去就行啦
$ cat ~/.ssh/id_rsa.pub

#如果上一步没有这个文件 我们就创建一个,运行下面命令(邮箱改成自己的哦),一路回车就好了
$ ssh-keygen -t rsa -C "youremail@example.com"
$ cat ~/.ssh/id_rsa.pub
  • window电脑

6. 测试一下
点开我们刚创建的项目,复制ssh的地址


将idea的springcloud项目和gitlab上的项目关联并提交

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发现代码成功提交


四. 在阿里云服务器上装了gitlab后发现服务器非常卡顿

解决办法1
上面不行用这个

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容