LoginSignup
1
2

More than 1 year has passed since last update.

AWS EC2にDocker ComposeでGitlabを導入

Last updated at Posted at 2021-06-21

事前準備

AWS EC2にDocker ComposeでJenkinsを導入 の続きとなります。

作業ディレクトリに移動

[ec2-user@ip-xxx-xx-xx-xxx container01]$ cd /home/docker/container01

docker-compose.ymlを編集

今回は試すにあたり、GitLab最小構成セットアップ(AWSに応用可) を参考にさせて頂きました。

  • AWS EC2にDockerでDocker Compose(1.29.2)を導入 にも記載しましたが、EC2のインスタンスタイプは「t2-medium」が最低レベルです。 ※複数コンテナ(Redmine, Jenkins, Gitlab)起動時、「t2-medium」でも何度かフリーズする事象が発生しています。
  • Gitlabのベースイメージには「gitlab/gitlab-ce:latest」を指定
  • 8000番ポートでアクセス
  • これまでRedmine, Jenkinsまではports指定のポート番号はシングルクォートで括っていなかったのですが、今回はシングルクォートで括らないと※1のエラーになり、ちょっとハマりかけました。(最初からシングルクォートで括る書き方していたら躓く事もないのでしょうが・・・)
version: '3.9'

services:

#前回の続きのため、Redmine, MySQL, Jenkins部分のコンテナ設定は割愛

  gitlab:
    image: gitlab/gitlab-ce:latest
    restart: always
    container_name: gitlab
    hostname: gitlab.example.com  #他の方法を試していた名残と思うので不要かも
    ports:
      - '8000:80'  #シングルクォートで括らないと※1のエラー
      - '4022:22'  #シングルクォートで括らないと※1のエラー
    environment:
      - GITLAB_HOST=xx.xxx.xxx.xxx  #elastic IPAdress(各自環境に応じて設定)
      - GITLAB_PORT=80
      - GITLAB_SSH_PORT=4022
      - GITLAB_ROOT_PASSWORD=root  #root 初期パスワード
    volumes:
      - /var/gitlab/config:/etc/gitlab
      - /var/gitlab/logs:/var/log/gitlab
      - /var/gitlab/data:/var/opt/gitlab
volumes:
  mysql-data:
    name: mysql-redmine

docker-composeコマンドを実行し、Dockerコンテナ(Gitlabのみ)をバックグラウンド起動

※1 以下は「docker-compose.yml」のports指定でポート番号をシングルクォートで括らずに実行した際のエラー(ご参考)

[ec2-user@ip-xxx-xx-xx-xxx container01]$ docker-compose up -d gitlab
Pulling gitlab (gitlab/gitlab-ce:latest)...
latest: Pulling from gitlab/gitlab-ce
345e3491a907: Pull complete
57671312ef6f: Pull complete
5e9250ddb7d0: Pull complete
7f815eeffff6: Pull complete
1a4fe87ef93e: Pull complete
eb13b56b9e19: Pull complete
2f19275b151e: Pull complete
84bbe8ae841a: Pull complete
0de204d1d029: Pull complete
Digest: sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Status: Downloaded newer image for gitlab/gitlab-ce:latest
Creating gitlab ... error

ERROR: for gitlab  Cannot create container for service gitlab: invalid port specification: "241342"

ERROR: for gitlab  Cannot create container for service gitlab: invalid port specification: "241342"
ERROR: Encountered errors while bringing up the project.

ports指定でポート番号を上記「docker-compose.yml」のようにシングルクォートで括り、再度Gitlabをバックグラウンド起動

[ec2-user@ip-xxx-xx-xx-xxx container01]$ docker-compose up -d gitlab
Creating gitlab ... done

Gitlab向けにEC2のポートを開放

作成した「docker-compose.yml」ではポート8000番を指定したため、EC2の「セキュリティグループ」を表示してインバウンドルールに8000番ポートを追加する必要があります。
EC2_Gitlab_8000番ポート開放.PNG

Gitlabにアクセス

ブラウザを起動し、 http://[Elastic IP アドレス]:8000/ にアクセスする。
以降、その後の画面遷移を参考としてキャプションを残しておきます。

  • ① 初期パスワード変更画面
    Gitlab_初期パスワード変更画面.PNG

  • ② ログイン画面
    Gitlab_ログイン画面.PNG

  • ③ Dashboard画面
    Gitlab_Dashboard画面.PNG

1
2
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
1
2