【问题标题】:Docker container not able to connect with docker container name as hostnameDocker 容器无法以 docker 容器名称作为主机名连接
【发布时间】:2023-04-07 10:07:01
【问题描述】:

我有一个 docker 网络,其中包含我的应用程序。我无法启动我的 selenium 应用程序以连接到 Web 应用程序,并且必须使用原始 IP 才能工作。如果我要使用我的 docker 容器名称作为主机名,则会出现以下错误。

收到错误:

ERROR: for ad622a7aeb92_traffic_app  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=120)

ERROR: for java  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=120)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 120).

Docker 网络:

[
    {
        "Name": "dummy_network",
        "Id": "06f5a0f36fa58c50faece96f09a358d9696a137fef1c13d465827c69c0325ba7",
        "Created": "2021-10-13T06:52:41.016380256Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "034cfe8afbe3bb40651a87742fa9fccbefee3b6ecb0bba9da0d224de8442f495": {
                "Name": "dummy_app_1",
                "EndpointID": "1bf4fb176bee5979e9dcbd65a1b12dd5ea5a8b7f4fbafeaf27c3146c9e032780",
                "MacAddress": "02:42:ac:12:00:06",
                "IPv4Address": "172.18.0.6/16",
                "IPv6Address": ""
            },
            "5d2e33ac8bb3aef1e1d7436cfbc247b254ab1d6978c23a44b5f2c831a88be66d": {
                "Name": "dummy_mysql",
                "EndpointID": "7f0d41a7d8d8cebd9dd4550c072a76b03cf2acf4916fa05aec5a9fb65b671a6c",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "872d20d9a9ae67e95244ab6082621fe16034a9677c265cf0d5f50f3854f6bbf5": {
                "Name": "traffic_app",
                "EndpointID": "39a58ffb2ac4569f3ccf7b87c545cd3cab7c0dcf3ba61529fc7c1ac54fe3819e",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

这是我的 docker-compose 文件,它连接到 dummy_network,但它似乎无法使用 docker 容器名称作为主机名连接到其他 docker 容器。 docker-compose文件:

version: "3.7"
networks:
  default:
    external: true
    name: dummy_network
services:
  java:
    container_name: traffic_app
    restart: always
    build: .

【问题讨论】:

  • UnixHTTPConnectionPool(host='localhost', port=None) 似乎您没有通过所显示的网络访问任何内容
  • 错误 UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=120) 表示您正在尝试访问 localhost,而不是 docker 容器端点。向问题添加更多信息,也许是您到达端点的代码
  • @SanilKhurana 这很奇怪,因为它直接来自尝试使用 Selenium 访问 Web 应用程序。它没有连接到本地主机

标签: python docker selenium


【解决方案1】:

解决了!发现我的容器没有主机名标签。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2019-06-15
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多