【问题标题】:How do I start a gitlab-ce container via docker-compose with admin credentials already set up?如何通过已设置管理员凭据的 docker-compose 启动 gitlab-ce 容器?
【发布时间】:2019-10-31 01:57:42
【问题描述】:

我有一个带有 Gitlab CE 容器的 docker-compose.yml 文件:

services:
  // other services..
  gitlab:
    image: 'gitlab/gitlab-ce'
    restart: always
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
      - "127.0.0.1:8081:80"
    volumes:
      - '/etc/gitlab'
      - '/var/log/gitlab'
      - '/var/opt/gitlab'
    networks:
      - backend

在启动时,这需要您打开浏览器,转到(在这种情况下)localhost:8081 并手动输入密码。

我希望这个过程自动化(用于本地开发和测试目的)。

Gitlab 自己的答案:

    gitlab-rails console production
    user = User.where(id: 1).first
    user.password = 'somethingsomething'
    user.password_confirmation = 'somethingsomething'
    user.save!
    exit

如果我在设置完所有内容后 ssh 进入 Gitlab CE 容器(需要几分钟),这会起作用。

直接通过command 运行它不起作用 - 大概是因为gitlab-rails console 在容器启动时还没有准备好运行。

我尝试使用gitlab/gitlab-ce 图像手动创建Dockerfile,使用COPY 将上述脚本放入容器并使用CMD 它。然而,正如预测的那样,这会失败,因为gitlab-rails console 尚未准备好启动。这需要一段时间。

理想的场景是容器启动、安装 Gitlab 并完成所有设置工作; 然后 自动设置 root 管理员密码。

【问题讨论】:

    标签: docker docker-compose gitlab


    【解决方案1】:

    解决方法是将GITLAB_OMNIBUS_CONFIG设置为环境变量。

    这行得通:

    services:
      // other services..
      gitlab:
        image: 'gitlab/gitlab-ce'
        restart: always
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            gitlab_rails['initial_root_password'] = 'adminadmin'
        ports:
          - '80:80'
          - '443:443'
          - '22:22'
          - "127.0.0.1:8081:80"
        volumes:
          - '/etc/gitlab'
          - '/var/log/gitlab'
          - '/var/opt/gitlab'
        networks:
          - backend
    

    在启动服务时,确认:

    gitlab_1       |               == Seed from /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/002_admin.rb
    gitlab_1       |               Administrator account created:
    gitlab_1       |               
    gitlab_1       |               login:    root
    gitlab_1       |               password: adminadmin
    

    【讨论】:

      【解决方案2】:

      这就是我解决这个问题的方法:

      sudo docker exec -it container_name bash
      // replace username by your user, for me it is root
      gitlab-rake "gitlab:password:reset[username]"
      

      【讨论】:

        【解决方案3】:

        我尝试了 cbll 响应,但对我不起作用。

        在 Docker Container Gitlab CE 中手动更改 root 密码。

        1. docker exec -it bash
        2. gitlab-rails 控制台

        -----等到控制台打开----

        1. irb(main):001:0> user = User.find_by_username 'root'

        2. irb(main):001:0> user.password = "newpassword"

        3. irb(main):001:0> user.confirmation_password = "newpassword"

        4. irb(main):001:0> user.save!

        【讨论】:

        • undefined method confirmation_password' for #<User id:1 @root>
        猜你喜欢
        • 2018-03-09
        • 2020-02-12
        • 1970-01-01
        • 2021-11-15
        • 2018-04-04
        • 1970-01-01
        • 2018-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多