程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题??

开发过程中遇到AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?的问题如何解决?下面主要结合日常开发的经验,给出你关于AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?的解决方法建议,希望对你解决AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?有所启发或帮助;

所以我有一个在 AWS ElasticBeanstalk(最新的 Docker 平台)上运行的多容器项目。

容器共享同一个桥接网络,因为它们需要能够相互通信(端口 3000、8080、9090、9100)。但是其中一个容器也需要能够与主机通信(端口 55113、56113)。

This is normally possible by just adding extra_hosts: "host.docker.internal:host-gateway" to that container and then using host.docker.internal instead of localhost inside the container,即 host.docker.internal:55113。我之前在 Debian 上成功使用过它。

但是这不适用于 AWS ElasticBeanstalk,连接被拒绝(请参阅下面的调试)。

我做错了吗?或者有什么解决办法?


AWS ElasticBeanstalk 平台:

Docker running on 64bit Amazon linux 2/3.4.2

主机的 Docker 和 Docker-Compose 版本:

$ sudo docker --version

Docker version 20.10.4,build d3cb89e

$ sudo docker-compose --version

docker-compose version 1.29.2,build unkNown

项目的docker-compose.yml:(仅展示相关部分)

version: "3.9"

services:
  prometheus:
    image: prom/prometheus:v2.28.1
    container_name: prometheus
    ports:
      - 9090:9090
    extra_hosts:
      - host.docker.internal:host-gateway # <-------- EXTRA HOST

networks:
  default:
    name: monitoring

容器调试:

$ sudo docker exec -it prometheus cat /etc/hosts

127.0.0.1   localhost
::1 localhost iP6-localhost iP6-loopBACk
fe00::0 iP6-localnet
ff00::0 iP6-mcastprefix
ff02::1 iP6-allnodes
ff02::2 iP6-allrouters
172.17.0.1  host.docker.internal # <-------- the mapPing is present
172.25.0.4  f01ffc6b2a8a

$ sudo docker exec -it prometheus wget host.docker.internal

ConnecTing to host.docker.internal (172.17.0.1:80)
wget: can't connect to remote host (172.17.0.1): Connection refused

$ sudo docker exec -it prometheus wget host.docker.internal:55113  # <-------- the port I want to reach

ConnecTing to host.docker.internal:55113 (172.17.0.1:55113)
wget: can't connect to remote host (172.17.0.1): Connection refused

Host 的 iptables(由 AWS 和/或 Docker 配置,我没有编辑):

$ sudo iptables -S

-P input ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-isolation-STAGE-1
-N DOCKER-isolation-STAGE-2
-N DOCKER-USER
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-isolation-STAGE-1
-A FORWARD -o br-a8a58f19c627 -m conntrack --ctstate RELATED,ESTABliSHED -j ACCEPT
-A FORWARD -o br-a8a58f19c627 -j DOCKER
-A FORWARD -i br-a8a58f19c627 ! -o br-a8a58f19c627 -j ACCEPT
-A FORWARD -i br-a8a58f19c627 -o br-a8a58f19c627 -j ACCEPT
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABliSHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A DOCKER -d 172.25.0.2/32 ! -i br-a8a58f19c627 -o br-a8a58f19c627 -p tcp -m tcp --dport 8080 -j ACCEPT
-A DOCKER -d 172.25.0.3/32 ! -i br-a8a58f19c627 -o br-a8a58f19c627 -p tcp -m tcp --dport 9100 -j ACCEPT
-A DOCKER -d 172.25.0.4/32 ! -i br-a8a58f19c627 -o br-a8a58f19c627 -p tcp -m tcp --dport 9090 -j ACCEPT
-A DOCKER -d 172.25.0.5/32 ! -i br-a8a58f19c627 -o br-a8a58f19c627 -p tcp -m tcp --dport 3000 -j ACCEPT
-A DOCKER-isolation-STAGE-1 -i br-a8a58f19c627 ! -o br-a8a58f19c627 -j DOCKER-isolation-STAGE-2
-A DOCKER-isolation-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-isolation-STAGE-2
-A DOCKER-isolation-STAGE-1 -j RETURN
-A DOCKER-isolation-STAGE-2 -o br-a8a58f19c627 -j DROP
-A DOCKER-isolation-STAGE-2 -o docker0 -j DROP
-A DOCKER-isolation-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN

主机的开放端口:

$ netstat -tuplen

ActivE internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:9090            0.0.0.0:*               ListEN      0          200315     -
tcp        0      0 127.0.0.1:55113         0.0.0.0:*               ListEN      1000       119886     -
tcp        0      0 0.0.0.0:9100            0.0.0.0:*               ListEN      0          200280     -
tcp        0      0 127.0.0.1:22221         0.0.0.0:*               ListEN      1001       197452     -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               ListEN      0          14121      -
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               ListEN      0          201081     -
tcp        0      0 127.0.0.1:56113         0.0.0.0:*               ListEN      1000       119890     -
tcp        0      0 127.0.0.1:38581         0.0.0.0:*               ListEN      0          20325      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               ListEN      0          18585      -
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               ListEN      0          201164     -
tcp        0      0 127.0.0.1:25            0.0.0.0:*               ListEN      0          16235      -
tcP6       0      0 ::1:55113               :::*                    ListEN      1000       119885     -
tcP6       0      0 :::111                  :::*                    ListEN      0          14124      -
tcP6       0      0 ::1:56113               :::*                    ListEN      1000       119889     -
tcP6       0      0 :::22                   :::*                    ListEN      0          18594      -
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          15762      -
udp        0      0 0.0.0.0:111             0.0.0.0:*                           0          14119      -
udp        0      0 127.0.0.1:323           0.0.0.0:*                           0          14990      -
udp        0      0 0.0.0.0:979             0.0.0.0:*                           0          14120      -
udP6       0      0 fe80::ed:19ff:fe84::546 :::*                                0          16539      -
udP6       0      0 :::111                  :::*                                0          14122      -
udP6       0      0 ::1:323                 :::*                                0          14991      -
udP6       0      0 :::979                  :::*                                0          14123      -

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?全部内容,希望文章能够帮你解决AWS ElasticBeanstalk 上的 Docker:“host.docker.internal:host-gateway”:连接被拒绝。 iptables 的问题?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。