GitLab Docker部署

2018/12/05 posted in  Docker
  1. 安装Docker

    sudo wget -qO- https://get.docker.com/ | sh
    
  2. 非root用户需要将用户加到docker用户组中

    sudo usermod -aG docker ubuntu
    
  3. 启动docker

    sudo service docker start
    
  4. 拉取gitlab-ce镜像

    sudo docker pull gitlab/gitlab-ce
    
  5. 启动gitlab-ce docker镜像

    sudo docker run --detach \
    --hostname gitlab.example.com \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

    具体的镜像命令可以参考gitlab官方文档

    如果是新安装的Ubuntu服务器,记得用ufw添加端口

    sudo ufw allow 80/tcp
    

设置默认的管理员账号密码

  1. 进入gitlab容器

    docker exec -it gitlab /bin/bash
    
  2. 进入rails

    cd /opt/gitlab/bin
    gitlab-rails console production
    
  3. 设置root用户密码

    irb(main):001:0> u = User.where(email: 'admin@example.com').first
    => #<User id:1 @root>
    irb(main):002:0> u.password
    => nil
    irb(main):003:0> u.password='12345678'
    => "12345678"
    irb(main):004:0> u.save!
    Enqueued ActionMailer::DeliveryJob (Job ID: b0e971db-4c6b-439c-82ee-86c7c277537e) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
    => true

邮件配置

  1. 进入gitlab容器

    docker exec -it gitlab /bin/bash
    
  2. 修改配置文件

    #vim /etc/gitlab/gitlab.rb,添加以下内容
    gitlab_rails['gitlab_email_enabled'] = true
    gitlab_rails['gitlab_email_from'] = 'gitlab@1234tv.com'
    gitlab_rails['gitlab_email_display_name'] = 'GitLab'
    gitlab_rails['gitlab_email_reply_to'] = 'noreply@1234tv.com'
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
    gitlab_rails['smtp_port'] = 465
    gitlab_rails['smtp_user_name'] = "gitlab@1234tv.com"
    gitlab_rails['smtp_password'] = "******"
    gitlab_rails['smtp_authentication'] = "login"
    gitlab_rails['smtp_enable_starttls_auto'] = true
    gitlab_rails['smtp_tls'] = true
  3. 重新加载配置文件,并验证是否生效

    gitlab-ctl reconfigure ##重新加载配置
    gitlab-rails console  ##进入rails
    

    输入 ActionMailer::Base.delivery_method:

    irb(main):002:0* ActionMailer::Base.delivery_method
    

    如果出现=>:smtp说明设置成功了