6

I have a docker-compose.yml file with a Gitlab CE container:

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

On startup, this requires you to open the browser, go to(in this case) localhost:8081 and manually input a password.

I'd like for this process to be automated(for local development and testing purposes).

Gitlab's own answers:

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

Which works if I ssh into the Gitlab CE container after everything is set up(takes minutes).

Running this directly via command does not work - presumably because the gitlab-rails console isn't ready to go yet the minute the container is up.

I've tried to manually create a Dockerfile with the gitlab/gitlab-ce image, used COPY to get the above script into the container and CMD it. However, as predicted, this fails as gitlab-rails console isn't ready yet on start-up. It takes a while.

Ideal scenario is that the container starts, installs Gitlab and does all the setup stuff; then sets the root admin password automatically.

cbll
  • 6,499
  • 26
  • 74
  • 117

3 Answers3

7

The solution is to set the GITLAB_OMNIBUS_CONFIG as an environment variable.

This works:

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

When starting up the service, this is confirmed:

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
cbll
  • 6,499
  • 26
  • 74
  • 117
2

This is how I fixed this issue on my side:

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

I try the cbll response but doesnt work for me.

To change the root password manually in Docker Container Gitlab CE.

  1. docker exec -it <git_lab_container> bash
  2. gitlab-rails console

-----Wait until the console open----

  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!

Ref_737
  • 1
  • 1