はじめに

GitLabCEを業務で使用しているのだが、Dockerではなく素でインストールされている。
※そもそも自分で構築したのだが
Dockerで構築する場合にはどのようにしたら良いのか知りたかったので実際に構築してみた。

環境

1
2
3
4
Windows 10 Professional
WSL2 (Ubunutu22.04 LTS)
docker version 20.10.24
Docker Compose version v2.17.2

準備

作業ディレクトリに移動し、下記を実行する。

1
export GITLAB_HOME=$HOME/gitlab-docker

構成

下記を作成する。

1
2
3
4
【作業ディレクトリ】(今回は、~/gitlab-dockerとする)
  ├── compose.yml
  └── gitlab
      └── Dockerfile

compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# https://hub.docker.com/r/gitlab/gitlab-ce

services:
  gitlab:
    build: ./gitlab
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG:
        external_url 'http://gitlab.example.com/'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    shm_size: '256m'

gitlab/Dockerfile

1
FROM gitlab/gitlab-ce:15.10.2-ce.0

下記で立ち上げる。(※立ち上げには時間がかかるので、 docker compose logs -f で確認しておくと良い)

1
docker compose up -d

初回ログイン

hosts に 127.0.0.1 gitlab.example.com と入れて、 http://gitlab.example.com/users/sign_in にアクセスする。

login-gitlab
とりあえずOKみたい。

パスワードについて

パスワードがわからないので調べてみると、下記でわかるようだ。
https://www.gitlab.jp/blog/2022/05/27/initial-password/

1
docker compose exec gitlab cat /etc/gitlab/initial_root_password

下記のように出てくる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ docker compose exec 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: WIhKtf/enmOoJyCkpNVGxXDqDgSoTe/OuH0lDBLfLJY=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
1
2
ID: root
PW: WIhKtf/enmOoJyCkpNVGxXDqDgSoTe/OuH0lDBLfLJY=

で入れる。

login-projects

プロジェクトの作成

  1. New Projectを押す。 create-new-project

  2. Create blank projectを押す。 create-blank-project

  3. test-project という名前で作成する。 create-test-project

作成できると画面遷移する。 created-test-project

プロジェクトのクローン & コミット + プッシュまで

  1. 適当な作業ディレクトリに移動し、 git clone をする。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
git clone http://gitlab.example.com/gitlab-instance-e29b5099/test-project.git

~/work$ git clone http://gitlab.example.com/gitlab-instance-e29b5099/test-project.git
Cloning into 'test-project'...
Username for 'http://gitlab.example.com': root
Password for 'http://[email protected]':
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
  1. 適当なファイルをつくってステージングし、コミットまで
1
2
cloneしたプロジェクトに移動する。
cd test-project/
1
2
3
4
5
6
# ファイルを作成
touch testfile
# ステージングする
git add -A
# コミット
git commit -m "Add testfile"
  1. プッシュする ※結構前に master -> main に変わっているので注意
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
git push origin main

$ git push origin main
Username for 'http://gitlab.example.com': root
Password for 'http://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 279 bytes | 279.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To http://gitlab.example.com/gitlab-instance-e29b5099/test-project.git
   e2ae154..f9ebfe5  main -> main
confirm-push

rootのパスワードを変更する

  1. 右上のアイコンから「Preference」を選択 change-root-password_1

  2. 左のメニューから「Password」を選択し、フォームに入力する。 change-root-password_2

root のパスワードになるので強力な文字列にしておくこと。
パスワードはランダム文字列で生成: https://www.luft.co.jp/cgi/randam.php

パスワードが変更完了したらログアウトされる。

  1. 変更したパスワードでログインできることを確認する。

補足: rootのパスワードを忘れた場合

docker compose exec gitlab cat /etc/gitlab/initial_root_password を実行した際に、下記のようなメッセージが出ているので、このリンクに従ってリセットすれば良い。

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.

確認: コンテナを削除してもデータが保持されているか

  1. ~/gitlab-docker に compose.ymlがあるので移動する。
1
cd ~/gitlab-docker
  1. コンテナを終了させる。
1
2
3
4
5
6
docker compose down

$ docker compose down
[+] Running 2/2
 ✔ Container gitlab-docker-gitlab-1  Removed                                                                                                                                                                       11.2s 
 ✔ Network gitlab-docker_default     Removed   
  1. コンテナを起動する
1
docker compose up -d
  1. ログインする ※できていればOK!

参考

おわりに

昔構築したときはけっこう大変だったけど、Dockerだとかなり楽に構築できる…。
業務で使用しているのものが既にパッケージ更新できない状態になっているので、(まあ社内にあるからいいのだけれども)
これを機にDockerの方にするのも良いかも。
アップグレード手順とか移行手順とかも調べておこうかなー。