我在AWS上创建了一个ec2实例。我已经成功地安装了Docker,并能够成功运行容器。但是,我无法让两个容器彼此通信。具体来说,我试图让Prometheus容器(端口9090)与Alertmanager容器(端口9093)通信。
我尝试了标准的桥接网络模式和主机网络模式的端口映射,但都没有成功。
在ec2本地主机上,是否需要特殊的魔法才能让两个容器彼此通信?
我的Prometheus配置:
rule_files:
- 'alert.rules'
scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- localhost:9090
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093
docker ps
的输出结果:CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c83d903a274 prom/prometheus "/bin/prometheus --c…" 22 hours ago Up 22 hours 0.0.0.0:9090->9090/tcp cranky_banach
d1404c0ee182 prom/alertmanager "/bin/alertmanager -…" 22 hours ago Up 22 hours 0.0.0.0:9093->9093/tcp competent_chatterjee
以下是来自CloudWatch的Prometheus日志行示例:
level=error ts=2019-07-19T20:31:36.001Z caller=notifier.go:528 component=notifier alertmanager=http://localhost:9093/api/v1/alerts count=1 msg="Error sending alert" err="Post http://localhost:9093/api/v1/alerts: dial tcp 127.0.0.1:9093: connect: connection refused"
这是
docker inspect bridge
命令的输出结果:[
{
"Name": "bridge",
"Id": "8ce9c8be6d071b098930a40873d54c5a6da68bcba91404e360cd0ca4532b365d",
"Created": "2019-07-19T10:02:37.509745972Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"1c83d903a2742a95323c626cb2e9a556908e6701790af79d61f8f9cf453acc0d": {
"Name": "cranky_banach",
"EndpointID": "23e33b9b0e2f2af24bd6da870bad625fe3d111d92f47a9fdf16d253eba9e3889",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"d1404c0ee18280a80fcfa96e7df3bfa5ff023a58f70b3bac67c23b31de7994df": {
"Name": "competent_chatterjee",
"EndpointID": "49b38cbf678abd3942f1d8b2a65f8b353b9e8e228cc84a9311cd1ac6549ddc96",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]