在Docker中安装GitLab, 配置QQ邮箱并与jenkins容器互联

参考链接

GitLab官方-在Docker中安装

GitLab官方- 配置腾讯企业邮箱

参考博客1

参考博客2

前提

  1. 正确安装Docker并配置镜像站
  2. 确保服务器有足够磁盘空间供GitLab镜像解压使用(可以使用df -h查看)

命令

安装

# 1 Installation
# 1.1 Change the server’s SSH port
vim /etc/ssh/sshd_config
Port = 2424 # change the SSH port
sudo systemctl restart ssh
sudo systemctl reboot

# 1.2 Set up the volumes location
sudo mkdir -p /srv/gitlab
export GITLAB_HOME=/srv/gitlab
##如果是第二次初始化安装, 需要删除`/srv/gitlab/`##

# 1.3 install
# 通过`dockerd`命令启动docker可以看到运行日志, 可以看到因为磁盘空间不足导致一直重新pull镜像
# 版本可以自选, 企业版: https://hub.docker.com/r/gitlab/gitlab-ee/tags/
# 社区版: https://hub.docker.com/r/gitlab/gitlab-ce/tags/
sudo docker run --detach \
  --hostname 本机IP地址或公网域名 \
  --env GITLAB_OMNIBUS_CONFIG="external_url 'http://本机IP地址或公网域名'" \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume $GITLAB_HOME/config:/etc/gitlab \
  --volume $GITLAB_HOME/logs:/var/log/gitlab \
  --volume $GITLAB_HOME/data:/var/opt/gitlab \
  --shm-size 256m \
      gitlab/gitlab-ee:17.2.0-ee.0

# 1.4 The initialization process may take a long time. You can track this process with:
sudo docker logs -f gitlab
# 1.5 Visit the GitLab URL, and sign in with the username root and the password from the following command:
# 用户名为root, 用下面的命令获取初始密码
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

配置QQ邮箱

# This container uses the official Linux package, so all configuration is done in the unique configuration file /etc/gitlab/gitlab.rb.
# 2.1 修改邮件配置
sudo docker exec -it gitlab /bin/bash
vi /etc/gitlab/gitlab.rb
# 配置
gitlab_rails['smtp_enable'] = true                                                                       
gitlab_rails['smtp_address'] = "smtp.qq.com"                                                             
gitlab_rails['smtp_port'] = 465                                                                          
gitlab_rails['smtp_user_name'] = "USERNAME@qq.com"                                                     
gitlab_rails['smtp_password'] = "authorization_code"                                                       
gitlab_rails['smtp_domain'] = "qq.com"                                                                   
gitlab_rails['smtp_authentication'] = "login"                                                            
# gitlab_rails['smtp_enable_starttls_auto'] = false                                                      
gitlab_rails['smtp_tls'] = true    
# gitlab_rails['smtp_pool'] = false
gitlab_rails['gitlab_email_from'] = 'USERNAME@qq.com' 
# 2.2 在容器中: 更新配置
gitlab-ctl reconfigure
# 2.3 在容器中: 测试邮件服务
gitlab-rails console # 进入邮件控制台, 需要1-2min
# 在启动的程序中输入
Notify.test_email('接收方邮件地址','邮件标题','邮件内容').deliver_now  # 发送测试邮件

jenkins和gitlab互通

jenkins在安装完成后, 会在docker中生成一个桥接网络, 需要把gitlab加入这个网络

# 查看当前所有网络
docker network ls
# 加入网络
docker network connect jenkins gitlab
# 检查容器所在的网桥
docker inspect -f '{{json .NetworkSettings.Networks}}' gitlab
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值