Docker搭建Gitlab

  1. 拉取镜像:docker pull gitlab/gitlab-ce
  2. 创建映射目录:
    mkdir -p /usr/local/gitlab/config
    mkdir -p /usr/local/gitlab/data
    mkdir -p /usr/local/gitlab/logs
  3. 运行容器:
docker run -d  -p 443:443 -p 8000:8000 -p 222:22 --name  gitlab --restart always -v /usr/local/gitlab/config:/etc/gitlab -v  /usr/local/gitlab/logs:/var/log/gitlab -v /usr/local/gitlab/data:/var/opt/gitlab gitlab/gitlab-c
  1. 修改gitlab.rb:vim /usr/local/gitlab/config/gitlab.rb
    把external_url改成部署机器的域名或ip地址,不加端口默认80
external_url 'http://192.168.202.130'
gitlab_rails['gitlab_shell_ssh_port'] = 222

如果被映射的端口不是80,需要修改

nginx['listen_port'] = 8000
external_url 'http://192.168.202.130:8000'
gitlab_rails['gitlab_shell_ssh_port'] = 222
  1. 修改gitlab.yml vim /usr/local/gitlab/data/gitlab-rails/etc/gitlab.yml
gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 192.168.202.130
    port: 8000
  1. 如果8080端口被Tomcat占用,会出现502的页面
    vim /usr/local/gitlab/config/gitlab.rb
# 假设有Tomcat占用了8080,因此改为8082试一试
  unicorn['listen'] = '127.0.0.1'
  1. 配置并启动GitLab
    进入容器:docker exec -ti gitlab /bin/bash
    刷新配置
gitlab-ctl reconfigure  #花时间比较多
gitlab-ctl restart    #改IP重启就可以了
  1. 退出并重启容器
docker restart gitlab
  1. 访问登录
192.168.202.130:8000

默认 user:root;password:root 登录是会重定向到修改密码界面

你可能感兴趣的:(docker,gitlab,容器)