3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Redmine/Gitlabをサブディレクトリを使って構築

Last updated at Posted at 2024-09-21

はじめに

今回はdockerを使って1つのマシンでredmine,gitlabを構築する方法について紹介します。

全体概要

全体の概要を以下に示します。クライアントがホストマシンにアクセスする際に、nginxコンテナを使ってredmineコンテナ、gitlabコンテナにアクセスを振り分けます。今回はrootにアクセスした際にredmineコンテナに振り分け、サブディレクトリでgitlabを指定したときにgitlabコンテナに振り分けるようにします。

sample1.png

フォルダ構成

フォルダ構成は以下です。

├── docker-compose.yml
├── dockerfiles
│   ├── gitlab.Dockerfile
│   ├── mysql.Dockerfile
│   ├── nginx.Dockerfile
│   └── redmine.Dockerfile
├── gitlab
├── mysql
├── nginx
│   └── conf.d
│       └── default.conf
└── redmine

手順

はじめに、docker-compose.ymlファイルの内容は以下です。

version: '3'
services:
  redmine:
    container_name: redmine_container
    restart: always
    build:
      context: .
      dockerfile: dockerfiles/redmine.Dockerfile
    networks:
      - redmine_gitlab_net
    volumes:
      - ./redmine/files:/usr/src/redmine/files
      - ./redmine/plugins:/usr/src/redmine/plugins
    ports:
      - 8081:3000
    environment:
      - TZ=Asia/Tokyo

  db:
    container_name: mysql_container
    build:
      context: .
      dockerfile: dockerfiles/mysql.Dockerfile
    networks:
      - redmine_gitlab_net
    volumes:
      - ./mysql/data:/var/lib/mysql
    environment:
      - TZ=Asia/Tokyo

  nginx:
    container_name: nginx_container
    build:
      context: .
      dockerfile: dockerfiles/nginx.Dockerfile
    networks:
      - redmine_gitlab_net
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
    ports:
      - 8080:80
    depends_on:
      - redmine
      - gitlab
    environment:
      - TZ=Asia/Tokyo

  gitlab:
    container_name: gitlab_container
    build:
      context: .
      dockerfile: dockerfiles/gitlab.Dockerfile
    networks:
      - redmine_gitlab_net
    volumes:
      - ./gitlab/config:/etc/gitlab
      - ./gitlab/logs:/var/log/gitlab
      - ./gitlab/gitlab/data:/var/opt/gitlab
    ports:
      - 8082:3001
    environment:
      - TZ=Asia/Tokyo

networks:
  redmine_gitlab_net:
    external: true

各コンテナのdockerfileの内容を順に示します。
以下はmysqlコンテナのdockerfileです。mysqlコンテナはredmineのチケットなどのデータを格納するために用います。

FROM mysql:8.0

ENV MYSQL_ROOT_PASSWORD=root_password
ENV  MYSQL_DATABASE=redmine
ENV  MYSQL_USER=redmine_user
ENV  MYSQL_PASSWORD=redmine_pass

以下がredmineのdockerfileです。

FROM redmine

RUN apt update && apt install vim -y

ENV REDMINE_DB_MYSQL=db
ENV REDMINE_DB_PASSWORD=redmine_pass
ENV REDMINE_DB_DATABASE=redmine
ENV REDMINE_DB_USERNAME=redmine_user

以下がnginxコンテナのdockerfileです。

FROM nginx:latest

最後に、以下がgitlabコンテナのdockerfileです。
gitlab.Dockerfile

FROM gitlab/gitlab-ce:12.2.1-ce.0
RUN apt update && apt install vim -y

nginxコンテナはリバースプロキシとして動作しますので、default.confに以下のように記載してください。サブディレクトリにアクセスが来た際にgitlabコンテナに振り分ける設定が記載されています。

server{
    listen 80;
    location /{
        proxy_pass http://redmine_container:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /gitlab{
        proxy_pass http://gitlab_container:3001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

上記ファイルの準備ができたら、docker-compose.ymlファイルの存在する階層で以下コマンドを実施してください。

docker-compose up -d

結果

結果は以下のようにrootにアクセスしたときはredmine、サブディレクトリにgitlabを指定するとgitlabが表示されます。

スクリーンショット 2024-09-21 11.49.24.png

スクリーンショット 2024-09-21 11.49.51.png

参考文献

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?