how do input array environments in docker-compose.yml

  Kiến thức lập trình

I’m using Docker-Compose to run Elasticsearch.
I want to set path.repo for snapshot by array.

 version: '2.1'
 services:
   elasticsearch:
     image: docker.elastic.co/elasticsearch/elasticsearch:6.4.3
     environment:
       - cluster.name=docker-cluster
       - bootstrap.memory_lock=true
       - node.name=es01
       - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
       - **'path.repo=["/usr/share/elasticsearch/book_backup/search_example", "/usr/share/elasticsearch/book_backup/agg_example"]'**  ==> not recognize.
  ulimits:
  memlock:
    soft: -1
    hard: -1
  volumes:
    - /Users/kkk/apps/elastic-cp/book_backup/search_example:/usr/share/elasticsearch/book_backup/search_example
    - /Users/kkk/apps/elastic-cp/book_backup/agg_example:/usr/share/elasticsearch/book_backup/agg_example
  ports:
    - "9200:9200"
    - "9300:9300"
  networks:
    - docker_net
  networks:
    docker_net:
    driver: bridge

So I set it like this but it doesn’t recognize the array.
What is the solution?

An array cannot be an environment variable, an environment variable can only be a pair of key value chains.

You can use several environnement variables or use others methods to pass this arguments.

1

I don’t know what means ‘**’ at environment section, but if we want pass array as environments variables in docker compose, use:

example:

- Vault:Kv:paths:0=path/data/infrastructure/mongo
- Vault:Kv:paths:1=path/data/infrastructure/redis
- Vault:Kv:paths:2=path/data/infrastructure/tefBus

LEAVE A COMMENT