简体   繁体   English

Docker-Compose无法解析容器名称?

[英]Docker-Compose can't resolve names of containers?

I have a wierd problem, as it seems to have been working fine until today. 我有一个比较棘手的问题,因为到今天为止似乎一直运转良好。 I can't tell what's changed since then, however. 但是,我不知道从那以后发生了什么变化。 I run docker-compose up --build --force-recreate and the build fails saying that it can't resolve the host name. 我运行docker-compose up --build --force-recreate ,构建失败,因为它无法解析主机名。

The issue is specifically because of CURL commands inside one of the Dockerfiles: 该问题特别是由于其中一个Dockerfile中的CURL命令引起的:

USER logstash
WORKDIR /usr/share/logstash
RUN ./bin/logstash-plugin install logstash-input-beats

WORKDIR /tmp
COPY templates/winlogbeat.template.json winlogbeat.template.json
COPY templates/metricbeat.template.json metricbeat.template.json

RUN curl -XPUT -H 'Content-Type: application/json' http://elasticsearch:9200/_template/metricbeat-6.3.2 -d@metricbeat.template.json
RUN curl -XPUT -H 'Content-Type: application/json' http://elasticsearch:9200/_template/winlogbeat-6.3.2 -d@winlogbeat.template.json

Originally, I had those commands running inside of the Elasticsearch Container, but it stopped working, reporting Could not resolve host: elasticsearch; Unknown error 最初,我有那些命令在Elasticsearch Container中运行,但是它停止工作,报告Could not resolve host: elasticsearch; Unknown error Could not resolve host: elasticsearch; Unknown error

I thought maybe it was trying to do the RUN commands too soon, so moved the process to the Logstash container, but the issue remains. 我以为可能是过早尝试执行RUN命令,因此将进程移至Logstash容器,但问题仍然存在。 Logstash depends on Elasticsearch, so Elastic should be up and running by the time that the Logstash container is trying to run this. Logstash取决于Elasticsearch,因此应在Logstash容器尝试运行Elastic时启动并运行Elastic。

I've tried deleting images, containers, network, etc but nothing seems to let me run these CURL commands during the build process; 我尝试删除图像,容器,网络等,但是似乎没有什么可以让我在构建过程中运行这些CURL命令。

I'm thinking that perhaps the Docker daemon is caching DNS names, but can't figure out how to reset it, as I've already deleted and recreated the network several times. 我在想,也许Docker守护进程正在缓存DNS名称,但由于我已经删除并重新创建了几次网络,因此无法弄清楚如何重置它。

Can anyone offer any ideas? 谁能提供任何想法?

Host: Ubuntu Server 18.04 主持人:Ubuntu Server 18.04

SW: Docker-CE (current version) SW:Docker-CE(当前版本)

ELK stack: All are the official 6.3.2 images provided by Elastic. ELK堆栈:全部是Elastic提供的官方6.3.2图像。

Docker-Compose.YML: 码头工人,Compose.YML:

version: '2'

services:

  elasticsearch:
    build:
      context: elasticsearch/
    volumes:
      - esdata:/usr/share/elasticsearch/data
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
#    ports:
#      - "9200:9200"
#      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx512m -Xms512m"
      HOSTNAME: "elasticsearch"
    networks:
      - elk

  logstash:
    build:
      context: logstash/
    volumes:
      - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro
    ports:
      - "5000:5000"
      - "5044:5044"
      - "5045:5045"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - elk
    depends_on:
      - elasticsearch

  kibana:
    build:
      context: kibana/
    volumes:
      - ./kibana/config/:/usr/share/kibana/config:ro
# Port 5601 is not exposed outside of the container
# Can be accessed through Nginx Reverse Proxy only
#    ports:
#      - "5601:5601"
    networks:
      - elk
    depends_on:
      - elasticsearch

  nginx:
    build:
      context: nginx/
    environment:
      - APPLICATION_URL=http://docker.local
    volumes:
      - ./nginx/conf.d/:/etc/nginx/conf.d:ro
    ports:
      - "80:80"
    networks:
      - elk
    depends_on:
      - elasticsearch

  fouroneone:
    build:
      context: fouroneone/
# No direct access, only through Nginx Reverse Proxy
#    ports:
#      - "8181:80"
    networks:
      - elk
    depends_on:
      - elasticsearch

networks:
  elk:
    driver: bridge

volumes:
  esdata:

Running a curl to elasticsearch is a wrong shortcut as it may not be up, plus Dockerfile may be the wrong place altogether 对Elasticsearch进行卷曲是一个错误的捷径,因为它可能没有启动,加上Dockerfile可能完全是错误的地方

Also I would not put this script in the Dockerfile but possibly use it to alter the ENTRYPOINT for the image if I really wanted to use Dockerfile (again I would not advise it) 另外,如果我真的想使用Dockerfile,我也不会将此脚本放在Dockerfile中,但可能会使用它来更改映像的ENTRYPOINT(再次建议不要这样做)

Best to do here is to have a logstash service in docker-file with the image on updated input plugin only and remove all the rest of lines in Dockerfile. 最好的做法是在docker-file中有一个logstash服务,仅在更新的输入插件上包含映像,并删除Dockerfile中的所有其余行。 And you could have a logstash_setup service which does the setup bits (using logstash image or even cleaner a basic centos image which should have bash and curl installed - since all you do is run a couple of curl commands passing some files) 而且您可能有一个logstash_setup服务来执行设置位(使用logstash映像或什至更清洁应安装bash和curl的基本centos映像-因为您要做的就是运行几个curl命令传递一些文件)

Script I am talking about might look something like this : 我正在谈论的脚本可能看起来像这样:

#!/bin/bash
set -euo pipefail
es_url=http://elasticsearch:9200
# Wait for Elasticsearch to start up before doing anything.
until curl -s $es_url -k -o /dev/null; do
    sleep 1
done
#then put your code here
curl -XPUT -H 'Content-Type: application/json' http://elasticsearch:9200/_ ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker-compose:Docker 容器无法使用服务名称进行连接 - Docker-compose: Docker containers can't connect using service names docker-compose在Docker for Mac中找不到服务或容器 - docker-compose can't find services or containers in Docker for Mac 码头工人组成 | 为什么容器不能互相到达? - Docker-Compose | why the containers can't reach each other? 无法使用docker-compose连接我的两个容器 - can't connect between my two containers with docker-compose docker-compose中的Docker容器无法通过主机名找到其他容器 - Docker container in docker-compose can't find other containers by hostname Docker - 无法在卷内的容器之间共享数据(docker-compose 3) - Docker - Can't share data between containers within a volume (docker-compose 3) 使 rails 和 sidekiq 从不同的 Docker 容器一起工作(但不能使用 docker-compose) - Make rails and sidekiq work together from different Docker containers (but can't use docker-compose) 容器以 docker-compose 开头,以 docker ps 列出,然后不以 docker-compose 出现 - Containers start with docker-compose up, are listed with docker ps, then don't appear with docker-compose 部署docker-compose容器 - Deploying docker-compose containers Docker-组成链接容器 - Docker-compose linking containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM