使用docker-compose部署gitlab服务

发布时间 2023-07-07 14:46:24作者: Ronnybox

前提条件:确保服务器都安装了docker以及docker-compose服务

? 创建docker-compose.yml

# 创建存放位置
mkdir -p /data/gitlab && cd /data/gitlab
touch docker-compose.yml

# external_url处请更换为您服务器的IP或域名。
cat > docker-compose.yml << EOF

version: '3.6'
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://172.31.2.212:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2224
    ports:
      - '8929:8929'
      - '2224:22'
    volumes:
      - '/data/gitlab/config:/etc/gitlab'
      - '/data/gitlab/logs:/var/log/gitlab'
      - '/data/gitlab/data:/var/opt/gitlab'
    shm_size: '256m'

EOF

? 本地创建挂载目录

# 在/data/gitlab目录下创建
cd /data/gitlab
mkdir config logs data

? 运行docker-compose

# 在docker-compose.yml文件目录中运行
[root@gitlab gitlab]# docker-compose up -d 
[+] Building 0.0s (0/0)   
[+] Running 2/2
 ✔ Network gitlab_default  Created 
 ✔ Container gitlab        Started

# 查看容器运行日志
# 创建时间可能较长,耐性等待
docker-compose logs -f 

浏览器访问Gitlab

  1. 浏览器输入: http://172.31.2.212:8929

img

  1. 获取root用户初始密码
[root@gitlab gitlab]#  docker exec -it gitlab cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: M4UXhVZe4VmGfVpmcrdQBk15MTf1iDrViwhWoxIMn8A=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

img

  1. 修改密码
    img

  2. 修改默认语言

修改后刷新浏览器页生效
img