简体   繁体   中英

Docker container not able to connect with docker container name as hostname

I have a docker network with my applications in them. I am unable to start my selenium application to connect to web apps and have to use the raw IP for it to work. If I were to use my docker container names as the hostname, an error occurs below.

Error received:

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 network:

[
    {
        "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": {}
    }
]

Here is my docker-compose file it connects to the dummy_network but it does not seem to be able to connect to other docker containers using the docker container name as hostnames. docker-compose file:

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

Solved. Found out that my containers did not have a hostname tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM