`docker-compose up` 和 `docker compose up`在环境变量方面有何不同?

3
我正在尝试使用Docker Compose将一个三节点的Elasticsearch集群部署到Azure容器实例。我松散地遵循Elasticsearch文档中的这个示例和ACI文档中的这个教程
当我尝试使用大多数文档中看到的标准docker-compose命令部署到ACI时,我会收到一个错误,提示不支持此操作:
> docker-compose -f .\docker-compose.yml -f .\docker-compose.production.yml up
ERROR: The platform targeted with the current context is not supported.
Make sure the context in use targets a Docker Engine.

当我尝试使用 ACI 文档中的 docker compose 命令(不带连字符)部署时,由于没有从 .env 文件加载环境变量,导致出现错误:

> docker compose -f .\docker-compose.yml -f .\docker-compose.production.yml up
1 error(s) decoding:

* error decoding 'Volumes[1]': invalid spec: certs:: empty section between colons

使用docker compose时,是否有一种方法可以加载.env文件,或者在ACI中使用docker-compose?我不完全理解docker compose命令来自何处以及为什么与docker-compose不同,它似乎不是一个标准的docker命令或CLI扩展,我找不到它。

这些是相关的文件:

docker-compose.yml

# Based on example from Elasticsearch documentation:
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker

version: '3.8'
services:

  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - ELASTIC_PASSWORD=$ELASTIC_PASSWORD 
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=true
      - xpack.security.http.ssl.key=$CERTS_DIR/es01/es01.key
      - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.http.ssl.certificate=$CERTS_DIR/es01/es01.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.verification_mode=certificate 
      - xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.transport.ssl.certificate=$CERTS_DIR/es01/es01.crt
      - xpack.security.transport.ssl.key=$CERTS_DIR/es01/es01.key
    volumes:
      - data01:/usr/share/elasticsearch/data
      - 'certs:$CERTS_DIR'
    ports:
      - 127.0.0.1:9200:9200
    networks:
      - elastic
    healthcheck:
      test: curl --cacert $CERTS_DIR/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
      interval: 30s
      timeout: 10s
      retries: 5
    ulimits:
      memlock:
        soft: -1
        hard: -1
    
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.http.ssl.key=$CERTS_DIR/es02/es02.key
      - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.http.ssl.certificate=$CERTS_DIR/es02/es02.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.verification_mode=certificate 
      - xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.transport.ssl.certificate=$CERTS_DIR/es02/es02.crt
      - xpack.security.transport.ssl.key=$CERTS_DIR/es02/es02.key
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
      - 'certs:$CERTS_DIR'
    networks:
      - elastic
  
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.http.ssl.key=$CERTS_DIR/es03/es03.key
      - xpack.security.http.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.http.ssl.certificate=$CERTS_DIR/es03/es03.crt
      - xpack.security.transport.ssl.enabled=true
      - xpack.security.transport.ssl.verification_mode=certificate 
      - xpack.security.transport.ssl.certificate_authorities=$CERTS_DIR/ca/ca.crt
      - xpack.security.transport.ssl.certificate=$CERTS_DIR/es03/es03.crt
      - xpack.security.transport.ssl.key=$CERTS_DIR/es03/es03.key
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
      - 'certs:$CERTS_DIR'
    networks:
      - elastic

  wait_until_ready:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    command: /usr/bin/true
    depends_on: {"es01": {"condition": "service_healthy"}}

volumes:
  data01:
  data02:
  data03:
  certs:

networks:
  elastic:
    driver: bridge

docker-compose.production.yml:

x-volume: &volume
  driver: azure_file
  driver_opts:
    share_name: acishare
    storage_account_name: <My Storage Account Name>

volumes:
  data01:
    <<: *volume
  data02:
    <<: *volume
  data03:
    <<: *volume
  certs:
    <<: *volume

.env

COMPOSE_PROJECT_NAME=es
CERTS_DIR=/usr/share/elasticsearch/config/certificates 
ELASTIC_PASSWORD=<Default Password>

我也尝试使用 env_file 属性,但是 docker compose 似乎忽略了它。
1个回答

4

根据这个GitHub问题的评论,似乎docker-compose是最初的Compose项目,其源代码存储在docker/compose仓库中。

docker compose是一个新的项目,实现了Compose规范,支持ECS和ACI,但还不支持本地部署。其源代码存储在docker/compose-cli仓库中。

根据这个问题docker compose目前还不支持.env文件。


2
Docker Compose 现在支持 .env 文件了... - AGI_rev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接