Docker如何部署gitlab

64 阅读2分钟

gitlab的简介

What is GitLab and why it is used?

GitLab is an open source code repository and collaborative software development platform for large DevOps and DevSecOps projects. GitLab is free for individuals. GitLab offers a location for online code storage and capabilities for issue tracking and CI/CD.

搭建步骤

docker拉去gitlab镜像

docker pull gitlab/gitlab-ce:latest

启动gitlab镜像

docker run \
 -itd  \
 -p 9980:80 \
 -p 9922:22 \
 -v /home/gitlab/etc:/etc/gitlab  \
 -v /home/gitlab/log:/var/log/gitlab \
 -v /home/gitlab/opt:/var/opt/gitlab \
 --restart always \
 --privileged=true \
 --name gitlab \
 gitlab/gitlab-ce

修改配置文件

#进入容器内部
docker exec -it gitlab /bin/bash


#修改gitlab.rb
vi /etc/gitlab/gitlab.rb
 
#加入如下
#gitlab访问地址,可以写域名。如果端口不写的话默认为80端口
external_url 'http://servicer-ip' 
#ssh主机ip
gitlab_rails['gitlab_ssh_host'] = 'server-ip'
#ssh连接端口
gitlab_rails['gitlab_shell_ssh_port'] = 9922


# 修改http和ssh配置
vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
 
  gitlab:
    host: server-ip
    port: 9980 # 这里改为9980
    https: false

容器内启动gitlab

    gitlab-ctl restart
      
    exit

浏览器访问

http://server-ip:9980/

修改root密码

# 进入容器内部
docker exec -it gitlab /bin/bash
 
# 进入控制台
gitlab-rails console -e production
 
# 查询id为1的用户,id为1的用户是超级管理员
user = User.where(id:1).first
# 修改密码为pdl123456
user.password='pdl123456'
# 保存
user.save!
# 退出
exit
 

可能遇到的问题 IpV4 forwarding is disabled 的解决办法

https://stackoverflow.com/questions/41453263

如何在gitlab内部载入gitee中的项目

step 1:

image.png

step 2:

image.png

step3:

image.png

如何在我的电脑上的git拉取gitlab上的仓库

clone

git clone ssh://git@server-ip:9922/xxxx/xxx.git

拉取某分支代码

git clone -b develop XXX

提交

step1: 配置ssh

#备注gitee,github,gitlab操作类似
参考链接:https://blog.csdn.net/weixin_51080921/article/details/123550636

step2:添加remote

git remote add ssh://git@server-ip:9922/xxxx/xxxx.git

step3:添加到本地、

git add .

step4:添加提交信息

git commit -m 'xxxxxxxxxxxxxxxxxxxxxxxxx'

更多

创建分支

git checkout -b dev

合并dev到master

#备注当前分支为master分支
git merge dev

如何在gitlab,gitee,gitlab上面查看代码

gitlab

image.png

gitee

image.png

github

image.png

image.png