GROWI を dockerでサクッと試す

![image.png](https://qiita-image-store.s3.amazonaws.com/0/34731/56b56eb6-fff9-34fa-684d-fd29e5384dab.png)

## 前提条件
1. ec2 (Amazon Linux 2)を使用
2. docker-compose はインストール済み
3. letsencryptを使ってSSLで接続する

## letsencrypt + nginx-proxy の設定
```bash
$ mkdir -p ~/docker/nginx-proxy
$ cd ~/docker/nginx-proxy
$ vim docker-compose.yml
```
```yaml
version: '3'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    restart: on-failure
    labels:
      - com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=jwilder/nginx-proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - proxy:/etc/nginx/vhost.d
      - proxy:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./certs:/etc/nginx/certs:ro
    network_mode: bridge

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    restart: on-failure
    depends_on:
      - nginx-proxy
    volumes:
      - proxy:/etc/nginx/vhost.d
      - proxy:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./certs:/etc/nginx/certs:rw
    network_mode: bridge

volumes:
  proxy:
```

### nginx-proxyの起動
```bash
$ docker-compose up -d
```

## install growi-docker-compose
```bash
$ cd ~/docker
$ git clone https://github.com/weseek/growi-docker-compose.git growi
$ cd growi
```

### docker-compose.yml を編集する

- コメントを参考に修正をします

```yaml
version: '3'

services:
  app:
    restart: on-failure # [追加]
    network_mode: bridge # [追加]
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 3000:3000 # [変更]
    links:
      - mongo:mongo
      - elasticsearch:elasticsearch
    depends_on:
      - mongo
      - elasticsearch
    environment:
      - VIRTUAL_HOST=growi.example.com # [追加] SSLで利用したいFQDN
      - LETSENCRYPT_HOST=growi.example.com # [追加] SSLで利用したいFQDN
      - LETSENCRYPT_EMAIL=info@example.com # [追加] letsencryptに登録するE-Mail
      - MONGO_URI=mongodb://mongo:27017/growi
      - ELASTICSEARCH_URI=http://elasticsearch:9200/growi
      - PASSWORD_SEED=change # [変更] ランダムな64文字に置き換える!!
      - FILE_UPLOAD=local
    command: "dockerize
              -wait tcp://mongo:27017
              -wait tcp://elasticsearch:9200
              -timeout 60s
              npm run server:prod"
    volumes:
      - growi_data:/data

  mongo:
    restart: on-failure # [追加]
    network_mode: bridge # [追加]
    image: mongo:3.4
    volumes:
      - mongo_configdb:/data/configdb
      - mongo_db:/data/db

  elasticsearch:
    restart: on-failure # [追加]
    network_mode: bridge # [追加]
    image: elasticsearch:5.3-alpine
    environment:
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"  # increase amount if you have enough memory
    command:
      - sh
      - -c
      - "./bin/elasticsearch-plugin list | grep -q analysis-kuromoji || ./bin/elasticsearch-plugin install analysis-kuromoji;
        ./bin/elasticsearch-plugin list | grep -q analysis-icu || ./bin/elasticsearch-plugin install analysis-icu;
        /docker-entrypoint.sh elasticsearch"
    volumes:
      - es_data:/usr/share/elasticsearch/data
      - es_plugins:/usr/share/elasticsearch/plugins
      - ./esconfig:/usr/share/elasticsearch/config

volumes:
  growi_data:
  mongo_configdb:
  mongo_db:
  es_data:
  es_plugins:
```

### growi-docker-compose の立ち上げ

```bash
$ docker-compose build
$ docker-compose up -d
```

## 最後に

これでしばらくすると、ブラウザで https://${LETSENCRYPT_HOST}/ にアクセスすると growiのログインページが表示されます。