docker - docker-compose down, up, stop 中抛出错误。 (命名卷 X 在服务 Y 中使用,但在卷部分中未找到声明。)

标签 docker elasticsearch docker-compose elastic-stack

我正在尝试使用 https://github.com/elastic/stack-docker 在 docker 中构建 ELK

但我只需要 Elasticsearch、Kibana 和 Logstash,所以我删除了所有 apm_server、filebeat 等东西。

然后,运行命令:

docker-compose -f setup.yml up

返回以下输出:

enter image description here

在那之后,每个 docker-compose 命令都抛出相同的错误:

ERROR: Named volume "es_data:/usr/share/elasticsearch/data:rw" is used in service "elasticsearch" but no declaration was found in the volumes section.

我的setup.yml是这样的:

version: "3.6"
services:
  setup:
    image: docker/compose:1.21.2
    working_dir: "${PWD}"
    cap_add: ['SYS_ADMIN']
    environment:
      - "PWD=${PWD}"
      - "ELASTIC_PASSWORD"
      - "ELASTIC_VERSION"
      - "TAG"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "${PWD}:${PWD}"
    entrypoint: ["/bin/ash", "-c"]
    command: ['cat ./scripts/setup.sh | tr -d "\r" | ash']

    # command: ["./scripts/setup.sh"]

还有我的 docker-compose.yml:

 ---
version: '3.6'
services:
  # The environment variable "TAG" is used throughout this file to
  # specify the version of the images to run. The default is set in the
  # '.env' file in this folder. It can be overridden with any normal
  # technique for setting environment variables, for example:
  #
  #   TAG=6.0.0-beta1 docker-compose up
  #
  # REF: https://docs.docker.com/compose/compose-file/#variable-substitution
  #
  # Also be sure to set the ELASTIC_VERSION variable. For released versions,
  # ${TAG} and ${ELASTIC_VERSION} will be identical, but for pre-release
  # versions, ${TAG} might contain an extra build identifier, like
  # "6.0.0-beta1-3eab5b40", so a full invocation might look like:
  #
  #   ELASTIC_VERSION=6.0.0-beta1 TAG=6.0.0-beta1-3eab5b40 docker-compose up
  #
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:${TAG}
    container_name: elasticsearch
    secrets:
      - source: ca.crt
        target: /usr/share/elasticsearch/config/certs/ca/ca.crt
      - source: elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
      - source: elasticsearch.keystore
        target: /usr/share/elasticsearch/config/elasticsearch.keystore
      - source: elasticsearch.key
        target: /usr/share/elasticsearch/config/certs/elasticsearch/elasticsearch.key
      - source: elasticsearch.crt
        target: /usr/share/elasticsearch/config/certs/elasticsearch/elasticsearch.crt
    ports: ['9200:9200']
    networks: ['stack']
    volumes:
      - 'es_data:/usr/share/elasticsearch/data'
      - './scripts/setup-users.sh:/usr/local/bin/setup-users.sh:ro'
    healthcheck:
      test: curl --cacert /usr/share/elasticsearch/config/certs/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
      interval: 30s
      timeout: 10s
      retries: 5

  kibana:
    image: docker.elastic.co/kibana/kibana:${TAG}
    container_name: kibana
    secrets:
      - source: kibana.yml
        target: /usr/share/kibana/config/kibana.yml
      - source: kibana.keystore
        target: /usr/share/kibana/data/kibana.keystore
      - source: ca.crt
        target: /usr/share/kibana/config/certs/ca/ca.crt
      - source: kibana.key
        target: /usr/share/kibana/config/certs/kibana/kibana.key
      - source: kibana.crt
        target: /usr/share/kibana/config/certs/kibana/kibana.crt
    ports: ['5601:5601']
    networks: ['stack']
    depends_on: ['elasticsearch']
    healthcheck:
      test: curl --cacert /usr/share/elasticsearch/config/certs/ca/ca.crt -s https://localhost:5601 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
      interval: 30s
      timeout: 10s
      retries: 5

  logstash:
    image: docker.elastic.co/logstash/logstash:${TAG}
    container_name: logstash
    secrets:
      - source: logstash.conf
        target: /usr/share/logstash/pipeline/logstash.conf
      - source: logstash.yml
        target: /usr/share/logstash/config/logstash.yml
      - source: logstash.keystore
        target: /usr/share/logstash/config/logstash.keystore
      - source: ca.crt
        target: /usr/share/logstash/config/certs/ca/ca.crt
    networks: ['stack']
    depends_on: ['elasticsearch']
    healthcheck:
      test: bin/logstash -t
      interval: 60s
      timeout: 50s
      retries: 5

secrets:
  ca.crt:
    file: ./config/ssl/ca/ca.crt
  logstash.yml:
    file: ./config/logstash/logstash.yml
  logstash.keystore:
    file: ./config/logstash/logstash.keystore
  logstash.conf:
    file: ./config/logstash/pipeline/logstash.conf
  elasticsearch.yml:
    file: ./config/elasticsearch/elasticsearch.yml
  elasticsearch.keystore:
    file: ./config/elasticsearch/elasticsearch.keystore
  elasticsearch.key:
    file: ./config/elasticsearch/elasticsearch.key
  elasticsearch.crt:
    file: ./config/elasticsearch/elasticsearch.crt
  elasticsearch.p12:
    file: ./config/elasticsearch/elasticsearch.p12
  kibana.yml:
    file: ./config/kibana/kibana.yml
  kibana.keystore:
    file: ./config/kibana/kibana.keystore
  kibana.key:
    file: ./config/kibana/kibana.key
  kibana.crt:
    file: ./config/kibana/kibana.crt

最佳答案

networks: {stack: {}}
# use docker volume to persist ES data outside of a container.
volumes:
  es_data:

这在您的 docker-compose.yml 中缺失。对照官方 repo 验证:https://github.com/elastic/stack-docker/blob/master/docker-compose.yml

关于docker - docker-compose down, up, stop 中抛出错误。 (命名卷 X 在服务 Y 中使用,但在卷部分中未找到声明。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55908931/

相关文章:

elasticsearch - Elasticsearch bool必须仅在文档中存在字段时

c# - 将对象序列化为 JSON,然后使用该对象在使用 NEST 的 Elasticsearch 中发送查询

ruby-on-rails - 无法停止或删除 Docker 容器 - 权限被拒绝错误

docker - ElasticSearch 无法恢复连接 : http://elasticsearch:9200/

git - "Peer' s 证书颁发者在 Openshift3 中已被标记为不被用户信任

python - Windows Docker - 在 python 中安装 Spacy 语言模型返回 ImportError : DLL load failed: The specified module could not be found

docker - 当Marathon在同一主机上运行所有docker应用程序时,docker服务停止

java - 如何使用ElasticSearch Rest高级客户端按任何字段中的任何单词进行搜索?

ruby-on-rails - 在 Docker 中使用 nginx 服务 Rails 的预编译 Assets

docker - 解决Docker容器网络的最佳方法