docker 容器中的网络不一致

Inconsistent networking in docker container

我在 windows 上使用 docker 在 docker 容器中 docker 化了一个烧瓶应用程序,我是 运行 debian wsl2 中的容器.我需要从这个容器向外部发送请求 api 但我得到这个错误:

(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f19fa4207f0>: Failed to establish a new connection: [Errno -5] No address associated with hostname')

但我可以在我的浏览器中访问该网站,我可以在 wsl 中访问它。并且对其他 api 的请求工作没有任何问题。 我也在 docker.

中使用默认网络

根据您对问题的描述,我想您必须检索容器主机的正确 IP 地址。

At this link 我描述了实现这个的方法:

1.通过以下方式检索 IP:

IP_ADDRESS=$(ip addr show | grep "\binet\b.*\bdocker0\b" | awk '{print }' | cut -d '/' -f 1)

2。在docker-compose YAML

里面赋值
extra_hosts:
      docker.host: ${IP_ADDRESS}

3。通过以下技巧将其传递给 docker compose

IP_ADDRESS=${IP_ADDRESS} docker-compose <YOUR_BUILDING_ARGUMENTS>