0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitLab in docker install メモ

Posted at

前書き

普段業務で普通に使っているGitLabだが、改めて自分でも構築してみようと思い
折角なので構築メモを残しておこうと思う

下調べ

2025年8月現在だとGitLabの提供方法は5種類ある
https://docs.gitlab.com/install/install_methods/

  • Linux package
  • Helm chart
  • GitLab Operator
  • Docker
  • Self-compiled

Microsoft Windowsは公式にサポートしていないと名言しているし、将来もサポートする予定がないと明記してある
https://docs.gitlab.com/install/install_methods/#microsoft-windows

GitLab is developed for Linux-based operating systems. 
It does not run on Microsoft Windows, and we have no plans to support it in the near future. 
For the latest development status, view this issue. Consider using a virtual machine to run GitLab.

今回は題名にしている通り、Dockerで構築する

先にWindowsはサポートしていないと記載したがそれならDocker for Windowsで動かせば良いのでは?という疑問が湧いてくるが、GitLabのDockerのインストールマニュアルを見るとDocker for Windowsもボリューム権限に関する既知の問題があり、サポートしていないようだ。

You must have a working Docker installation that is not Docker for Windows. 
Docker for Windows is not officially supported as the images have known compatibility issues with volume permissions and potentially other unknown issues. 
If you are trying to run on Docker for Windows, see the getting help page.
This page contains links to community resources (like IRC or forums) where you can seek help from other users.

構築メモ

公式のDockerインストール手順に則りインストールを進める
https://docs.gitlab.com/install/docker/installation/

前提条件のDocker Compose, Docker Engine, Docker Swarnは既にインストール済みなので割愛
sshポートの設定も完了

1. ボリューム用ディレクトリの作成から実施していく

説明によるとこのディレクトリはconfigやログやデータ用に利用するらしい
https://docs.gitlab.com/install/docker/installation/#create-a-directory-for-the-volumes

Create a directory for the configuration files, logs, and data files. 

自分はworkディレクトリ配下に作成し、作成したディレクトリへをGITLAB_HOMEの環境変数として設定する

📁 ~/work ❯ mkdir gitlab
📁 ~ ❯ vi .zshrc 
📁 ~ ❯ cat .zshrc | tail -n 1
export GITLAB_HOME=/Users/XX/work/gitlab

2. GitLabのバージョン確認

まずGitLab EEかGitLab CEか決める必要がある
自分は試しで使うのでCEでバージョンはlatestでいく
https://hub.docker.com/r/gitlab/gitlab-ce/tags/

スクリーンショット 2025-08-10 14.06.59.png

3. Docker Composeを使用してGitLabをインストールする

Dockerを利用したインストールはやり方が3つある

  • Docker Compose
  • Docker Engine
  • Docker Swarm

自分はDocker Composeを利用してインストールする
https://docs.gitlab.com/install/docker/installation/#install-gitlab-by-using-docker-compose

既にDocker Composeはインストールされているので公式に倣ってdocker-compose.ymlを作成する

imageは前述の手順で確認したCEのlatestに書き換え
portは9000番台を利用することにした

📁 ~/work/gitlab ❯ vi docker-compose.yml
📁 ~/work/gitlab ❯ cat docker-compose.yml 
services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        # Add any other gitlab.rb configuration here, each on its own line
        external_url 'http://gitlab.example.com'
    ports:
      - '9000:80'
      - '9443:443'
      - '22:22'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'

ファイルを作成したので起動していく

📁 ~/work/gitlab ❯ docker compose up -d
[+] Running 10/10
 ✔ gitlab Pulled                                                                                         59.7s 
   ✔ 385cf9daee56 Pull complete                                                                          54.4s 
   ✔ c9c96a1baa68 Pull complete                                                                           0.3s 
   ✔ 9d01589fc4e3 Pull complete                                                                           0.7s 
   ✔ e3bd89a9dac5 Pull complete                                                                           1.7s 
   ✔ 9dd64c1502aa Pull complete                                                                           2.0s 
   ✔ 861fb8d4094e Pull complete                                                                           0.8s 
   ✔ 11ae3edc7bbf Pull complete                                                                           0.7s 
   ✔ e2f8fe778890 Pull complete                                                                           0.8s 
   ✔ b20d802c6d90 Pull complete                                                                           0.5s 
[+] Running 2/2
 ✔ Network gitlab_default  Created                                                                        0.0s 
 ✔ Container gitlab        Started                                                                        0.6s 

ブラウザで以下のリンクにアクセスするとGitLabが起動してきた
http://localhost:9000/users/sign_in

スクリーンショット 2025-08-10 14.34.04.png

4. Docker Containerで実行されるGitLabを構成する

GitLabのUIにログインするパスワードだがコンテナにログイン後、以下のファイルに記載がある

  • ファイル名: /etc/gitlab/initial_root_password

コンテナにログインして確認するもよし

📁 ~/work/gitlab ❯ docker exec -it gitlab /bin/bash

ワンライナーで確認してもいい

📁 ~/work/gitlab ❯ docker exec -it gitlab editor /etc/gitlab/initial_root_password

ログインに成功するとGitLabの画面が表示される
スクリーンショット 2025-08-10 14.40.54.png

ちなみに構築時点ではGitLabのlatestイメージを利用するとバージョンは18.2だった
スクリーンショット 2025-08-10 14.42.03.png

あとは自由に使う!

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?