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.
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