在 docker 网络中的容器之间连接

时间:2021-02-16 15:58:45

标签: docker docker-compose

我已将 docker-compose 文件设置为连接到外部网络,如下所示:

networks:
  backend:
    external:
      name: app-network

然后将网络添加到每个容器中

    networks:
      - backend

我也在为我的 nginx 容器做这件事。当我运行 wget http://localhost:8004/ -q -O - 时,它成功返回源代码。但是,当我从网络中的一个容器运行它时,它没有获取源代码。

容器似乎已成功添加到网络:

[
    {
        "Name": "app-network",
        "Id": "5c5ed53b3837e1c784b9b7f7ac9dd6ff1786e52159e33194ed986ec63b3fcd42",
        "Created": "2021-02-16T16:41:49.068787748+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.16.0/20",
                    "Gateway": "192.168.16.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "54357d1bfde9c7dcfc9ca4ae8804ec14a844fb047fefa22bfdafc15a4b8a07bc": {
                "Name": "elasticsearch",
                "EndpointID": "42f420c4976e116562945ad27e0a57785246e036159d75b868575ccfb8ab0b08",
                "MacAddress": "02:42:c0:a8:10:06",
                "IPv4Address": "192.168.16.6/20",
                "IPv6Address": ""
            },
            "5ccfad66a3995761d4b86fa9007dbe7a8e53b83c8fe65477c851944feba127da": {
                "Name": "vue-storefront-api_redis_1",
                "EndpointID": "47d48c065b1e18fb748da7eea32197f0b8984923930f1938599061c93c5f01f9",
                "MacAddress": "02:42:c0:a8:10:05",
                "IPv4Address": "192.168.16.5/20",
                "IPv6Address": ""
            },
            "90e4943fecd7145e01874a1dbbfe483105b01bf7b24dc90ec7244d8526959d82": {
                "Name": "02-store_nginx_1",
                "EndpointID": "4a9c586d0ccb97a4b7b2c7d58c7e24da1062b1dcedbdb0d76e42f3395f91c55c",
                "MacAddress": "02:42:c0:a8:10:04",
                "IPv4Address": "192.168.16.4/20",
                "IPv6Address": ""
            },
            "936e3994f39bee0e530fa6abbb832e646b7254d068c49f0a3df40675f7ff5e76": {
                "Name": "vue-storefront-api_kibana_1",
                "EndpointID": "425be601669607429c334f075a164fa02c572961912271cd82e59d2fbbcc55b7",
                "MacAddress": "02:42:c0:a8:10:07",
                "IPv4Address": "192.168.16.7/20",
                "IPv6Address": ""
            },
            "cb85c99c7b65c21605b29cb0f0b927985c69489073907935d96429763374d308": {
                "Name": "vue-storefront-api_app_1",
                "EndpointID": "ccc70ec9a3ea48057fa0646a49da2b9765224c3b4c7815fab79873fa8b368b22",
                "MacAddress": "02:42:c0:a8:10:08",
                "IPv4Address": "192.168.16.8/20",
                "IPv6Address": ""
            },
            "e9441aa78ca9f741ea4813f86f43c27438126c91cafb9897e3aac26d85622b3e": {
                "Name": "02-store_db_1",
                "EndpointID": "0864f74cf585ed1068926a42e2419cdf3235f6d831f91061a45b157cab7deee3",
                "MacAddress": "02:42:c0:a8:10:02",
                "IPv4Address": "192.168.16.2/20",
                "IPv6Address": ""
            },
            "e9bfb008fe599a46c319df8193f8acbf6fdd8e0cfafd822334c5e18b7372d9b9": {
                "Name": "02-store_php_1",
                "EndpointID": "5fa6812af20bbac021a072f32b972dd31005e49f2f3028efc473a63be688d0e3",
                "MacAddress": "02:42:c0:a8:10:03",
                "IPv4Address": "192.168.16.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

我做错了什么?

0 个答案:

没有答案