【问题标题】:Docker localhost IPDocker 本地主机 IP
【发布时间】:2015-11-16 00:42:54
【问题描述】:

我在笔记本电脑上运行各种容器:

X1C3:~$ docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                    NAMES
4daccb82531d        prom/prometheus:latest   "/bin/prometheus -con"   12 hours ago        Up 12 hours         0.0.0.0:9090->9090/tcp   berserk_goldstine
32c2c31e0d5f        prom/blackbox-exporter   "/bin/go-run -config."   12 hours ago        Up 12 hours         0.0.0.0:9115->9115/tcp   goofy_wescoff
7490523a3bc7        prom/node-exporter       "/bin/go-run"            2 days ago          Up 2 days                                    sharp_albattani
61303633672b        prom/alertmanager        "/bin/go-run -config."   2 days ago          Up 2 days           0.0.0.0:9093->9093/tcp   goofy_kare
89ce4f49c426        grafana/grafana          "/usr/sbin/grafana-se"   2 days ago          Up 2 days           0.0.0.0:3000->3000/tcp   berserk_wozniak

至少从其中一个容器中,prom/prometheus 我需要与其他容器通信。

例如这里是一个典型的配置:

global:
 scrape_interval: 10s
 evaluation_interval: 10s
scrape_configs:
 - job_name: 'prometheus'
   target_groups:
    - targets:
      - localhost:9090
      - 192.168.88.161:9100
 - job_name: 'blackbox'
   metrics_path: /probe
   params:
     module: [icmp]
     target: [8.8.8.8]
   target_groups:
     - targets:
       - 192.168.88.161:9115

我发现我需要指定192.168.88.161,因为 localhost 不起作用。我猜是因为 localhost 似乎是该容器的本地。然而,192.168.88.161 的烦人之处在于它只是我在家时的 IP。我的IP 变化,因为我一直在变化。那么如何处理这个问题呢?

我推测使用 X1C3.local,但我认为如果没有 bonjour 发现可以跨容器工作(值得怀疑!)

【问题讨论】:

  • 你可以将容器链接到另一个容器吗?

标签: docker prometheus


【解决方案1】:

如果您使用 docker-machine 和 docker 1.9,引用容器的新方法是通过 discovery service,例如 consul,再加上像 registrator 这样的检查员服务。

另一种类似的方法是使用 swarm 来管理这些服务(仍然与 consul 耦合)

在所有情况下,这意味着至少还有两个容器(一个用于 consul master,一个用于像 swarm master 或 registrator 这样的检查)。
见“What is the different between putting a separate service discovery and integrate it into the cluster machine in Docker Swarm”。

相对于--link 的优势在于您可以按任何顺序启动容器,它们可以停止并重新启动,并且它们仍然可以从另一个中看到。
--link 表示您链接到的容器具有要先启动,然后它会停止并重新创建,--link 将不再有效。

发现服务方法也适用于本地主机或多个主机。 (--link 只能在本地工作,不能跨主机)

【讨论】:

  • 发现服务听起来太复杂了。特别是如果它不使用 mdns (Bonjour)。我要试试链接!
【解决方案2】:

我现在开始做的是在我的/etc/prometheus.yml 中使用localhost,并在所有服务上使用docker run--net=host 选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 2018-11-13
    • 2020-09-04
    相关资源
    最近更新 更多