概要
Parallesを使ってM1 MacにUbuntu ARM64をインストールして、Gitlab Dockerイメージを動作させる。ARMプロセッサ搭載のLinuxベースのNASでGitlabを動かしてみたく、そのために事前に動作確認してみた。
環境
- MacBook Pro (M1): macOS 14.2.1 Build 23C71
- Parallels Desktop 19 for Mac Standard Edition 19.2.1 (54832)
- Ubuntu 22.04.3 LTS (Jammy Jellyfish)
- Docker version 24.0.7, build afdd53b
事前準備
Parallels Desktopをインストールする。
Ubuntu ARM64のインストール
Ubuntu ARM64をインストールする。手順はParallels Desktopを使用して、Apple M1チップ搭載のMacに新しいLinuxシステムをインストールするを参照。
Docker Engineのインストール
Docker EngineをUbuntuにインストールする。手順はInstall Docker Engine on Ubuntuを参照。
Dockerのaptリポジトリの設定
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Dockerのパッケージをインストール
最新バージョンをインストール
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Docker Engineの動作確認
hello-worldイメージを使って動作確認
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
478afc919002: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Gitlab Dockerイメージの作成と動作確認
Gitlab Dockerイメージを使っての一連の流れはGitLab Docker imagesに載っていて、概ねこれに沿ってやってみた。
注意点として、ARM64に対応するDockerイメージがDocker Hubでは公開されていない。なのでGitLab Docker Image for ARM64を参考にしてイメージを作成した。
Dockerイメージの作成
Ubuntu上でイメージを作成する。GitLab Docker Image for ARM64をgit cloneしてから下記コマンドを実行する。今回使用するのはGitLab 16.7 Community Edition (CE)。
docker build . -t gitlab-ce:16.7.0-ce.0 \
--build-arg RELEASE_PACKAGE=gitlab-ce \
--build-arg RELEASE_VERSION=16.7.0-ce.0
Dockerコンテナの実行
GitLab CEのDockerコンテナを実行する。GITLAB_HOME
の設定はSet up the volumes locationに説明が載っている。
export GITLAB_HOME=/home/foo/workspace/gitlab # あらかじめubuntuにユーザfooを作ってある想定
docker run --detach \
--publish 8443:443 --publish 8080:80 --publish 2222:22 \
--name gitlab \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 256m \
gitlab-ce:16.7.0-ce.0
各オプションの意味は、
- --detach: コンテナをバックグラウンドで実行
- --publish 8443:443 --publish 8080:80 --publish 2222:22: ホストの8443ポートをコンテナの443ポート、ホストの8080ポートをコンテナの80ポート、ホストの2222ポートをコンテナの22ポートにマッピング
- --volume \$GITLAB_HOME/config:/etc/gitlab --volume \$GITLAB_HOME/logs:/var/log/gitlab --volume \$GITLAB_HOME/data:/var/opt/gitlab: ホストの
$GITLAB_HOME/config
をコンテナの/etc/gitlab
に、ホストの$GITLAB_HOME/logs
をコンテナの/var/log/gitlab
に、ホストの$GITLAB_HOME/data
をコンテナの/var/opt/gitlab
にマウント - --shm-size 256m: コンテナの共有メモリサイズ256MB
Gitlabのrootパスワードの取得
下記コマンドを実行してGitlabのrootパスワードを取得する。実行中のDockerコンテナ内の/etc/gitlab/initial_root_password
ファイルから'Password:'という文字列を検索して表示する。
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
このパスワードは24時間で消えるとのこと ("The password file will be automatically deleted in the first reconfigure run after 24 hours."と書かれている)。
Gitlabへのログインの確認
Mac側からUbuntuへのSSH接続の際にポート8080をポートフォワーディングするように設定したうえで、UbuntuのIPアドレスにポート8080でブラウザでアクセスするとログイン画面が表示される。
さきほど取得したパスワードでrootログインできることを確認する。
補足:ポートフォワーディングの設定
例えば、UbuntuのIPアドレスが10.211.55.10で、ユーザfooで接続する場合のMac側のssh configの記述例は下記のようになる。
Host ubuntu_arm64
Hostname 10.211.55.10 # 実際に環境に合わせて設定する
User foo
LocalForward 8080 localhost:8080
今後
作成したGitlab DockerイメージをARMプロセッサ搭載のLinuxベースのNASで動かしたい。