ubuntu

ubuntu gitlab容器化部署方案

小樊
51
2025-07-18 01:04:08
栏目: 智能运维

在Ubuntu上通过Docker容器化部署GitLab是一个相对简单且高效的方法。以下是详细的步骤指南:

准备工作

  1. 安装Docker: 对于基于Debian的系统(如Ubuntu),使用以下命令:

    sudo apt-get update
    sudo apt-get install -y curl openssh-server ca-certificates tzdata
    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
    sudo apt-get install gitlab-ce
    
  2. 安装Docker Compose(可选但推荐):

    curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    

部署步骤

  1. 创建 docker-compose.yml 文件: 在你的主机上创建一个名为 docker-compose.yml 的文件,内容如下:

    version: '3.6'
    services:
      gitlab:
        image: gitlab/gitlab-ee:latest
        container_name: gitlab
        restart: always
        ports:
          - '5480:80'  # GitLab web interface
          - '5443:443' # GitLab HTTPS
          - '5022:22'   # SSH
        volumes:
          - './config:/etc/gitlab'
          - './logs:/var/log/gitlab'
          - './data:/var/opt/gitlab'
        shm_size: '256m'
    
  2. 启动GitLab容器: 在包含 docker-compose.yml 文件的目录中运行以下命令来启动GitLab容器:

    docker-compose up -d
    
  3. 访问GitLab: 启动容器后,你可以通过浏览器访问 http://<your-server-ip>:5480 来访问GitLab的Web界面,并使用默认的root账户登录。

配置GitLab

  1. 修改配置文件: 进入容器并修改配置文件:
    docker exec -it gitlab /bin/bash
    
    编辑 /etc/gitlab/gitlab.rb 文件,设置外部URL和其他必要的配置项,然后重载配置:
    gitlab-ctl reconfigure
    gitlab-ctl restart
    

注意事项

通过以上步骤,你应该能够在Ubuntu上成功部署GitLab。如果在部署过程中遇到问题,可以参考GitLab的官方文档或相关社区资源。

0
看了该问题的人还看了