LoginSignup
171
206

More than 5 years have passed since last update.

Docker-ComposeでGitLabとRedmineとJenkinsを立ち上げる

Last updated at Posted at 2016-01-10

書店のコンピュータ関係の棚に、最近、Dockerという言葉をよく見かけるようになったので、年末年始にDockerについて調べてみました。
その中で、RedmineやらGitLabやらのイメージを取り込んで簡単に環境が構築できると知り、試しにやってみましたので、構築手順のメモを残します。

環境

  • CentOS Linux release 7.2.1511 (Core)

手順

OSの設定

CentOSのアップデート

とりあえず OSのアップデートを行います。

# yum update -y

ファイヤーウォールとSELinuxの無効化

必要なのか分かりませんがファイヤーウォールとSELinuxは無効にした方が良さそうです。

ファイヤーウォールとSELinuxの無効化
# systemctl disable firewalld
# vi /etc/selinux/config
...
SELINUX=disabled
...

再起動

設定変更後はいったん再起動を行います。

再起動
# reboot

OSバージョン

本記事掲載時のOSバージョンは以下のような感じです。

# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

Dockerのインストール

CentOSでは、Dockerを"yum install -y docker"でインストール出来るようなのですが、この場合は最新バージョンがインストールされませんでした。
Dockerの公式サイトにある記述に従って、docker.repoファイルを作成します。

docker.repoファイルの作成
# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

ようやくDockerをインストールします。

dockerのインストール
# yum install docker-engine

なんかDockerのサービスを起動しておくようです。

Dockerサービスの開始
# service docker start
バージョンの確認
# docker -v
Docker version 1.9.1, build a34a1d5

Docker-Composeのインストール

Dockerでは1つのコンテナに1つの機能を持たせるのが一般的なようです。
たとえば、Redmine用のコンテナ、RedmineのMySQL用のコンテナ、GitLab用のコンテナ・・・などの感じです。
これらを一つ一つコマンドで起動させるのは面倒で仕方がないと思っていたら、当然、複数のコンテナを管理するDocker-Composeというツールがあるようなのでそちらを用います。
こちらもDockerの公式サイトに手順があるのでそのままです。

Docker-Composeを取得
# curl -L https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
実行権限を付与
# chmod +x /usr/local/bin/docker-compose

以下のコマンドを実行するとTabキーでの補完が有効になるようです。

Tabキーの補完の有効化
# curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose --version | awk 'NR==1{print $NF}')/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
バージョンの確認
# docker-compose version
docker-compose version 1.5.2, build 7240ff3
docker-py version: 1.5.0
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013

Docker-Composeで GitLabとRedmineとJenkinsの環境を用意する

Docker-Composeで一気に環境を用意します。
いろいろと調べた結果、以下のファイルを用意すればいけそうです。

docker-compose.yml

GitLabの部分はこちら
Redmineの部分はこちら
の記述を参考に、MySQLを使ったり、GITLAB_RELATIVE_URL_ROOTの設定を変更しています。
portsのオプションは、nginxでリバースプロキシを使ってアクセスできるようにしているため不要です。
その他のオプションは詳しく調べていません。

docker-compose.yml
gitlab-mysql:
  restart: always
  image: sameersbn/mysql:latest
  environment:
    - DB_USER=gitlab
    - DB_PASS=password
    - DB_NAME=gitlabhq_production
  volumes:
    - /srv/docker/gitlab/mysql:/var/lib/mysql
gitlab:
  restart: always
  image: sameersbn/gitlab:8.3.2
  links:
    - gitlab-redis:redisio
    - gitlab-mysql:mysql
  environment:
    - DEBUG=false
    - TZ=Asia/Tokyo
    - GITLAB_TIMEZONE=Tokyo

    - GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string

    - GITLAB_HOST=
    - GITLAB_PORT=
    - GITLAB_SSH_PORT=
    - GITLAB_RELATIVE_URL_ROOT=/gitlab

    - GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
    - GITLAB_NOTIFY_PUSHER=false

    - GITLAB_EMAIL=notifications@example.com
    - GITLAB_EMAIL_REPLY_TO=noreply@example.com
    - GITLAB_INCOMING_EMAIL_ADDRESS=reply@example.com

    - GITLAB_BACKUP_SCHEDULE=daily
    - GITLAB_BACKUP_TIME=01:00

    - SMTP_ENABLED=false
    - SMTP_DOMAIN=www.example.com
    - SMTP_HOST=smtp.gmail.com
    - SMTP_PORT=587
    - SMTP_USER=mailer@example.com
    - SMTP_PASS=password
    - SMTP_STARTTLS=true
    - SMTP_AUTHENTICATION=login

    - IMAP_ENABLED=false
    - IMAP_HOST=imap.gmail.com
    - IMAP_PORT=993
    - IMAP_USER=mailer@example.com
    - IMAP_PASS=password
    - IMAP_SSL=true
    - IMAP_STARTTLS=false
  volumes:
    - /srv/docker/gitlab/gitlab:/home/git/data
gitlab-redis:
  restart: always
  image: sameersbn/redis:latest
  volumes:
    - /srv/docker/gitlab/redis:/var/lib/redis
redmine-mysql:
  restart: always
  image: sameersbn/mysql:latest
  environment:
    - DB_USER=redmine
    - DB_PASS=password
    - DB_NAME=redmine_production
  volumes:
    - /srv/docker/redmine/mysql:/var/lib/mysql
redmine:
  restart: always
  image: sameersbn/redmine:latest
  links:
    - redmine-mysql:mysql
  environment:
    - TZ=Asia/Tokyo

    - REDMINE_PORT=
    - REDMINE_HTTPS=false
    - REDMINE_RELATIVE_URL_ROOT=/redmine
    - REDMINE_SECRET_TOKEN=

    - REDMINE_SUDO_MODE_ENABLED=false
    - REDMINE_SUDO_MODE_TIMEOUT=15

    - REDMINE_CONCURRENT_UPLOADS=2

    - REDMINE_BACKUP_SCHEDULE=
    - REDMINE_BACKUP_EXPIRY=
    - REDMINE_BACKUP_TIME=

    - SMTP_ENABLED=false
    - SMTP_METHOD=smtp
    - SMTP_DOMAIN=www.example.com
    - SMTP_HOST=smtp.gmail.com
    - SMTP_PORT=587
    - SMTP_USER=mailer@example.com
    - SMTP_PASS=password
    - SMTP_STARTTLS=true
    - SMTP_AUTHENTICATION=:login

    - IMAP_ENABLED=false
    - IMAP_HOST=imap.gmail.com
    - IMAP_PORT=993
    - IMAP_USER=mailer@example.com
    - IMAP_PASS=password
    - IMAP_SSL=true
    - IMAP_INTERVAL=30
  volumes:
    - /srv/docker/redmine/redmine:/home/redmine/data
jenkins:
  restart: always
  image: jenkins:latest
  environment:
    - JENKINS_OPTS=--prefix=/jenkins
  volumes:
    - /srv/docker/jenkins/jenkins:/var/jenkins_home
proxy:
  build: proxy
  links:
    - gitlab:gitlab
    - redmine:redmine
    - jenkins:jenkins
  ports:
    - "80:80"

Dockerfile

nginx用のDockerfile。docker-compose.ymlのproxyの部分で、このDockerfileを使ってnginxのイメージがビルドされます。

Dockerfile
# https://registry.hub.docker.com/_/nginx/
FROM nginx:latest

# 設定ファイルをコピー
COPY nginx.conf /etc/nginx/nginx.conf

# HTMLファイルをコピー
COPY index.html /usr/share/nginx/html/index.html

nginx.conf

通常だとコンテナ側のポートをホスト側のポートに割り当てるため、GitLabでは10080のポートだったり、Redmineでは10081のポートでアクセスすることになるようですが、http://127.0.0.1/gitlab などのようにアクセスしたかったので、nginxのリバースプロキシという機能を使ってみる。
docker-compose.ymlのproxyのlinksというオプションで書いた、gitlabやredmineの変数にnginx.confからアクセスできるらしい。
いろいろ試してみて以下のような感じでやりたいことが実現できた。

nginx.conf
user  nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
  worker_connections  1024;
}

http {
  include  /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;

  sendfile           on;
  keepalive_timeout  65;
  server_tokens      off;

  server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name 127.0.0.1;
    charset koi8-r;

    client_max_body_size 1024M;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;

    # static-html
    location / {
      index index.html;
      root /usr/share/nginx/html;
    }
    # gitlab
    location /gitlab {
      proxy_pass http://gitlab;
    }
    # redmine
    location /redmine {
      proxy_pass http://redmine;
    }
    # jenkins
    location /jenkins {
      proxy_pass http://jenkins:8080;
    }
  }
}

nginx.confは参考にしたサイトごとに書き方が違うため、上記が正しいかは自信がない・・・。

ディレクトリ構成

とりあえず、index.htmlは適当に作成し、上記で作成したファイルを以下のようなディレクトリ構成で配置する。

ディレクトリ構成
docker
├─ docker-compose.yml
└─ proxy
  ├─ Dockerfile
  ├─ nginx.conf
  └─ index.html

Jenkinsの共有ディレクトリの設定

なぜかJenkinsだけ、そのままだとホスト側の共有ディレクトリにコンテナ側から書き込むことができないため、chmodで1000を設定しておきます。

オーナーの変更
# mkdir -p /srv/docker/jenkins/jenkins
# chmod 1000 /srv/docker/jenkins/jenkins

Docker-Composeの実行

docker-compose.ymlを格納したディレクトリに移動し、Docker-Composeで一気にコンテナを用意します。

docker-composeの実行
# docker-compose up -d

アクセス

ブラウザから以下のアドレスでそれぞれの環境にアクセスすることができるようになります。

  • GitLab:http://127.0.0.1/gitlab
    • root/5iveL!fe
  • Redmine:http://127.0.0.1/redmine
    • admin/admin
  • Jenkins:http://127.0.0.1/jenkins

注意

まだ、実際の運用はしていませんので問題が起こる可能性があります。

171
206
1

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
171
206