在Docker Compose的卷中指定NFS

最近我了解到一种技术,就是Docker Compose的Volumes可以挂载NFS存储。

我试了一下,为了不忘记,我做了笔记。顺便说一下,这次是关于运行一个名为Growi的开源软件的Wiki的例子。

Docker Compose的版本如下。

$ docker-compose -v
docker-compose version 1.21.2, build a13347

我获取了Growi官方发布的docker-compose.yml文件。

weseek/growi-docker-compose: growi-docker-compose – 启动 GROWI 的最快方式

这里有。

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 127.0.0.1:3000:3000    # localhost only by default
    links:
      - mongo:mongo
      - elasticsearch:elasticsearch
    depends_on:
      - mongo
      - elasticsearch
    environment:
      - MONGO_URI=mongodb://mongo:27017/growi
      - ELASTICSEARCH_URI=http://elasticsearch:9200/growi
      - PASSWORD_SEED=changeme
      # - FILE_UPLOAD=local    # activate this line if you use local storage of server rather than AWS
      # - MATHJAX=1            # activate this line if you want to use MathJax
      # - PLANTUML_URI=http:// # activate this line and specify if you use your own PlantUML server rather than public plantuml.com
    command: "dockerize
              -wait tcp://mongo:27017
              -wait tcp://elasticsearch:9200
              -timeout 60s
              npm run server:prod"
    volumes:
      - growi_data:/data

  mongo:
    image: mongo:3.4
    volumes:
      - mongo_configdb:/data/configdb
      - mongo_db:/data/db

  elasticsearch:
    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:

比较长,但大致是这个样子。

由于当前状态,没有为卷设置特定值,所以将其保存在主机的 /var/lib/docker/volumes 目录下。

通过将其更改为以下方式,您可以将保存位置更改为NFS存储。

volumes:
  growi_data:
    driver_opts:
      type: nfs
      o: "addr=192.168.1.2,hard,rsize=1048576,wsize=1048576,nfsvers=4"
      device: ":/volume1/wiki-data/growi_data"
  mongo_configdb:
    driver_opts:
      type: nfs
      o: "addr=192.168.1.2,hard,rsize=1048576,wsize=1048576,nfsvers=4"
      device: ":/volume1/wiki-data/mongo_configdb"
  mongo_db:
    driver_opts:
      type: nfs
      o: "addr=192.168.1.2,hard,rsize=1048576,wsize=1048576,nfsvers=4"
      device: ":/volume1/wiki-data/mongo_db"
  es_data:
    driver_opts:
      type: nfs
      o: "addr=192.168.1.2,hard,rsize=1048576,wsize=1048576,nfsvers=4"
      device: ":/volume1/wiki-data/es_data"
  es_plugins:
    driver_opts:
      type: nfs
      o: "addr=192.168.1.2,hard,rsize=1048576,wsize=1048576,nfsvers=4"
      device: ":/volume1/wiki-data/es_plugins"

可以传递参数到 o 以便在 NFS 挂载时使用。

只需像往常一样运行docker-compose up,即可自动挂载并使用。

广告
将在 10 秒后关闭
bannerAds