我有一个docker compose文件,该文件启动了几个容器,包括prometheus,alertmanager和grafana。这些容器无法连接到Internet。我尝试了多种解决方案,但无济于事。 我在Digitalocean ubuntu小滴上。
我的docker-compose文件:
version: '3'
services:
prometheus:
image: prom/prometheus:v2.20.1
container_name: prometheus
ports:
- 9090:9090
volumes:
- /data/prometheus:/prometheus
- ./prometheus/:/etc/prometheus/
restart: always
alertmanager:
image: prom/alertmanager:v0.21.0
container_name: alertmanager
ports:
- 9093:9093
- 6783:6783
command:
- '--log.level=debug'
- '--config.file=/etc/alertmanager/alertmanager_config.yml'
- '--storage.path=/alertmanager'
volumes:
- ./alertmanager:/etc/alertmanager
- /data/alertmanager:/alertmanager
restart: always
grafana:
image: grafana/grafana:7.1.5
container_name: grafana
ports:
- 3000:3000
volumes:
- ./grafana.ini:/etc/grafana/grafana.ini
restart: always
我尝试了很多事情
service docker restart
{
"dns" : ["172.24.100.50", "8.8.8.8"]
}
nameserver 127.0.0.11
options ndots:0
到
nameserver 127.0.0.11
nameserver 172.24.100.50
nameserver 8.8.8.8
命令在容器内运行
/alertmanager $ wget http://curl.haxx.se/download/curl-7.36.0.tar.gz
wget: bad address 'curl.haxx.se'
/alertmanager $ nslookup google.com
;; connection timed out; no servers could be reached
/alertmanager $
在发送警报时,alertmanager会显示错误:
lookup api.<my website>.com on 172.24.100.50:53: read udp 172.18.0.5:44178->172.24.100.50:53: i/o timeout"
我尝试在主机网络上运行alertmanager,但仍然无法正常工作
docker run --net host -d prom/alertmanager:v0.21.0
docker exec -it <container_id> sh
/alertmanager $ cat /etc/resolv.conf
nameserver 172.24.100.50
nameserver 8.8.8.8
/alertmanager $ ls
/alertmanager $ wget http://curl.haxx.se/download/curl-7.36.0.tar.gz
wget: bad address 'curl.haxx.se'
/alertmanager $ set vc
/alertmanager $ nslookup google.com
;; connection timed out; no servers could be reached
我尝试了许多选择,但尚未找到解决方案。有人可以帮助我吗?让我知道是否需要更多详细信息。
答案 0 :(得分:0)
很可能您的主机iptables规则正在阻止。
在您的主机上,仔细检查iptables -L -v -n
的输出。或者暂时尝试iptables -P INPUT ACCEPT
之类的东西,然后在确认其正常工作后,使用iptables -P INPUT DROP
将其还原。要访问外部世界而不是本地docker dns,请用FORWARD替换INPUT。
答案 1 :(得分:0)
我能够解决问题。事实证明,在digitalocean防火墙中有小滴,出站流量被UDP阻止。仅允许TCP通信。因此,DNS解析无法正常工作。
DNS uses TCP for Zone transfer and UDP for name queries either regular (primary) or reverse. UDP can be used to exchange small information whereas TCP must be used to exchange information larger than 512 bytes.
DNS需要端口53来进行名称解析,并且从docker日志中可以看到端口53正在使用中,但是由于udp出站流量被阻止,因此dns无法正常工作。
但是,我确实尝试通过设置dns_opt = use-vc设置来强制docker使用TCP。这没用。允许UDP流量,现在可以正常工作。