本文最后更新于 2024-12-19,文章内容可能已经过时。

拉取镜像

docker pull gitlab/gitlab-ce

创建docker-compose

version: '3'
networks:
  net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.24.0.0/24
          gateway: 172.24.0.1

services:
  gitlab-ce:
    image: gitlab/gitlab-ce
    container_name: gitlab
    hostname: gitlab
    #environment:
    #  GITLAB_OMNIBUS_CONFIG: |
    #    external_url 'http://gitlab.elsworld.cn:8102'
    #    gitlab_rails['gitlab_shell_ssh_port'] = 8122
    
    privileged: true
    restart: always
    volumes:
      - /mnt/docker/Configs/gitlab/opt:/var/opt/gitlab
      - /mnt/docker/Configs/gitlab/log:/var/log/gitlab
      - /mnt/docker/Configs/gitlab/etc:/etc/gitlab
    ports:
      - 8102:8102

      - 8122:22

    tty: true
    stdin_open: true
    networks:
      net:
        ipv4_address: 172.24.0.4

运行docker-compose

docker-compose up -d

修改配置

打开${Docker_Config}/gitlab/etc目录

# 进入gitlab目录
cd your/docker/config/path/gitlab/etc
# 编辑gitlab.rb文件
vim gitlab.rb
## GitLab URL
external_url  'https://gitlab.elsworld.cn:8102'

### Gravatar Settings   
gitlab_rails['gravatar_plain_url']  =  'http://cdn.sep.cc/avatar/%{hash}?s=%{size}&d=identicon'  
gitlab_rails['gravatar_ssl_url']  =  'https://cdn.sep.cc/avatar/%{hash}?s=%{size}&d=identicon'

################################################################################  
## GitLab NGINX  
##! Docs: https://docs.gitlab.com/omnibus/settings/nginx.html  
################################################################################
nginx['enable']  =  true  
nginx['redirect_http_to_https']  =  true  
nginx['redirect_http_to_https_port']  =  8443
nginx['ssl_certificate']  =  "/etc/gitlab/ssl/gitlab.elsworld.cn.crt"  
nginx['ssl_certificate_key']  =  "/etc/gitlab/ssl/gitlab.elsworld.cn.key"

################################################################################  
################################################################################  
##                Configuration Settings for GitLab CE and EE                 ##  
################################################################################  
################################################################################  
  
################################################################################  
## gitlab.yml configuration  
##! Docs: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/gitlab.yml.md  
################################################################################  
gitlab_rails['enable']  =  true  # do not disable unless explicitly told to do so in docs  
  
gitlab_rails['gitlab_ssh_host']  =  'gitlab.elsworld.cn'

### GitLab Shell settings for GitLab  
gitlab_rails['gitlab_shell_ssh_port']  =  8122

打开${Docker_Config}/gitlab/opt/gitlab-rails/etc目录

# 进入 gitlab 目录
cd your/docker/config/path/opt/gitlab-rails/etc
# 编辑 gitlab.yml 文件
vim gitlab.yml
# This file is managed by gitlab-ctl. Manual changes will be  
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb  
# and run `sudo gitlab-ctl reconfigure`.  
  
production:  &base  
  #  
  # 1. GitLab app settings  
  # ==========================  
  
  ## GitLab settings  
  gitlab:  
  ## Web server settings (note: host is the FQDN, do not include http://)  
  host:  gitlab.elsworld.cn  
  port:  8102  
  https:  true