使用Docker快速部署Gitlab

使用Docker部署Gitlab

1. 下载gitlab镜像

docker pull gitlab/gitlab-ce

2. 运行gitlab实例

GITLAB_HOME=`pwd`/data/gitlab
docker run -d \
    --hostname gitlab \
    --publish 8443:443 --publish 80:80 --publish 2222: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 \
    gitlab/gitlab-ce

3. 配置gitlab实例

3.1 配置邮箱:

docker exec -t -i gitlab vim /etc/gitlab/gitlab.rb

下面以网易163邮箱为例配置邮箱:

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxxx@163.com"
gitlab_rails['smtp_password'] = "xxxxpassword"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_openssl_verify_mode'] = "peer"

gitlab_rails['gitlab_email_from'] = "xxxx@163.com"
user["git_user_email"] = "xxxx@163.com"

下面以qq邮箱为例配置邮箱:

gitlab_rails['smtp_enable'] = true 
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com" 
gitlab_rails['smtp_port'] = 465 
gitlab_rails['smtp_user_name'] = "邮箱地址" 
gitlab_rails['smtp_password'] = "password" 
gitlab_rails['smtp_authentication'] = "login" 
gitlab_rails['smtp_enable_starttls_auto'] = true 
gitlab_rails['smtp_tls'] = true 
gitlab_rails['smtp_domain'] = "exmail.qq.com" 
gitlab_rails['gitlab_email_from'] = '邮箱地址' 

注意以上的xxxx@163.com代表用户名,即邮箱地址,而xxxxpassword不是邮箱的登陆密码而是网易邮箱的客户端授权密码, 再网易邮箱web页面的设置-POP3/SMTP/IMAP-客户端授权密码查看。

gitlab-ctl reconfigure

gitlab-ctl restart

3.2 配置外部访问URL

这个必须配置,否则默认以容器的主机名作为URL,刚开始由于做了端口映射80->8080, 因此设置为

external_url "http://10.103.240.36:8080"

后来发现external_url只能配置ip或者域名,不能有端口,否则不能启动
于是只能把端口设置为80->80,然后external_url设置为:

external_url "http://10.103.240.36"

4. 重启gitlab

docker restart gitlab

参考yml

version: '2'
services:
    gitlab:
      image: 'twang2218/gitlab-ce-zh:latest'
      restart: unless-stopped
      hostname: 'gitlab.example.com'
      environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://gitlab.example.com'
          gitlab_rails['time_zone'] = 'Asia/Shanghai'
          # 需要配置到 gitlab.rb 中的配置可以在这里配置,每个配置一行,注意缩进。
          # 比如下面的电子邮件的配置:
          # gitlab_rails['smtp_enable'] = true
          # gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
          # gitlab_rails['smtp_port'] = 465
          # gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
          # gitlab_rails['smtp_password'] = "password"
          # gitlab_rails['smtp_authentication'] = "login"
          # gitlab_rails['smtp_enable_starttls_auto'] = true
          # gitlab_rails['smtp_tls'] = true
          # gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
      ports:
        - '80:80'
        - '443:443'
        - '2222:22'
      volumes:
        - config:/etc/gitlab
        - data:/var/opt/gitlab
        - logs:/var/log/gitlab
volumes:
    config:
    data:
    logs:

关于xmsg

技术面前人人平等.同时技术也不分高低贵贱.正所谓学无大小,达者为尊.
此条目发表在未分类分类目录。将固定链接加入收藏夹。

发表评论