Cannot connect to AWS Mqtt endpoint inside docker container - docker
I am using the AWS IOT SDK java client to connect to an AWS Mqtt endpoint. If run it locally, it works fine.
Then I wrap up my application inside a docker container and use docker-compose to run it, the application just stuck at where it try to make the connection to the endpoing.
However, if I change the docker container's network mode to host:
network_mode: "host"
It works again.
So I guess there is something wrong with the container network configuration. Do I need to expose any ports specific to the Mqtt (like port 443?) But that does not work as well.
Updated the network setting below:
[
{
"Name": "2234_emulator",
"Id": "af69dba44fc91922e50c883c80852c0be2d6a87218e5d9821a1331547d39e343",
"Created": "2022-02-12T14:23:19.298315542Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.20.0.0/16"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"0dc64743c4643d972ae5bc9010416880321bb2fde8ad3afd6834fa6d1eaa0cf6": {
"Name": "2234_ScannerService_1",
"EndpointID": "1c362f48ec0f4afcd1fe705103c0867fe54d874ddb42f678580edcaf0a23e892",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
},
"5d79cb8e56f7a7789f1860bfc0f48077b326736762c2c13238883bac2a5b40d1": {
"Name": "2234_DeviceEmulatorService_1",
"EndpointID": "8f4170c876d527edb22c4ff47ff167d28b86eeb10c78943fdfedd086237c8c26",
"MacAddress": "02:42:ac:14:00:0f",
"IPv4Address": "172.20.0.15/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "emulator",
"com.docker.compose.project": "2234",
"com.docker.compose.version": "1.27.0"
}
},
{
"Name": "2234_main",
"Id": "b588bb5a545ae0e82f8d13f693d6447024ccf475428e18f31caa7bb4eb9c6102",
"Created": "2022-02-12T14:23:19.205307729Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.128.0/20",
"Gateway": "192.168.128.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"0cca77c4db7b0a12d2d61e7cfc2d2357a8dc4214997ec212340331def380c235": {
"Name": "2234_ServiceA_1",
"EndpointID": "15d775a2692032800d986390ee2a2b672466c00172dd3cd334fa1f16096ca0b4",
"MacAddress": "02:42:c0:a8:80:09",
"IPv4Address": "192.168.128.9/20",
"IPv6Address": ""
},
"0dc64743c4643d972ae5bc9010416880321bb2fde8ad3afd6834fa6d1eaa0cf6": {
"Name": "2234_ServiceA_1",
"EndpointID": "134a2b629c98420a80575e622299acd11a03d9cb150aa68c7d71ef942950fa5a",
"MacAddress": "02:42:c0:a8:80:0e",
"IPv4Address": "192.168.128.14/20",
"IPv6Address": ""
},
"148494a3f1e0b2d182adc735cace01c91e2f3c365009f476b86503c87b8903fb": {
"Name": "2234_ServiceA_1",
"EndpointID": "1ca44d5a3fe1f3d81b9a03eaf89a8cd7fc343e0cdc3bfe27a805de2b6cbfd0bb",
"MacAddress": "02:42:c0:a8:80:07",
"IPv4Address": "192.168.128.7/20",
"IPv6Address": ""
},
"1b180c5f62bcd28eb3a28d0c0d682b50080a846f2ccca24a8cf2540f0c95cd6c": {
"Name": "2234_ServiceA_1",
"EndpointID": "730db6763b208d4a6e32c1b20bdd5fc56a0f00340f675411001e05e389235a8f",
"MacAddress": "02:42:c0:a8:80:0f",
"IPv4Address": "192.168.128.15/20",
"IPv6Address": ""
},
"1c3bf13eee59444abcd225637fb6661fb64bac49d0380063b848f9563bbe08b6": {
"Name": "2234_ServiceA_1",
"EndpointID": "585da3c62513f512c6fe2942a4dd8a23c7ff574cc7f8c75ca59ca3e36c369d9e",
"MacAddress": "02:42:c0:a8:80:0c",
"IPv4Address": "192.168.128.12/20",
"IPv6Address": ""
},
"23fc36057ded2b07b4d7963b91960c51a088c4c67a41b4993c11a57f735c91c3": {
"Name": "2234_ServiceA_1",
"EndpointID": "ff36e613c9a8517caafbc5dc37b1b442fad588f0328d2b5cd1902286fd4ecb84",
"MacAddress": "02:42:c0:a8:80:0a",
"IPv4Address": "192.168.128.10/20",
"IPv6Address": ""
},
"2785da15585da3080e6b98b47556b6da191ab8c25b008516654dab0cc06c19e2": {
"Name": "2234_main_1",
"EndpointID": "297c57e418c2e079e41a4b9d1dcfcea60bcfad888d3287465d44c5d00761643f",
"MacAddress": "02:42:c0:a8:80:02",
"IPv4Address": "192.168.128.2/20",
"IPv6Address": ""
},
"27d50157f4e8664756f36233527892e8c4aa2e0afc723f8ba3e23d4820cbd78d": {
"Name": "2234_ServiceA_1",
"EndpointID": "9ca872fb98dd8b9a229cf86975c3e38789679929d7d3e375c292119fdeb4c963",
"MacAddress": "02:42:c0:a8:80:06",
"IPv4Address": "192.168.128.6/20",
"IPv6Address": ""
},
"3260d6123a96496dc0b59984ca95d72db7ae688ea8daad92b7a0fbb47ec56207": {
"Name": "2234_ServiceA_1",
"EndpointID": "037755d88f02225c41be13206e7c406828ef3dff9767939367af43dd1498dd49",
"MacAddress": "02:42:c0:a8:80:0b",
"IPv4Address": "192.168.128.11/20",
"IPv6Address": ""
},
"4b999440f80b9c9e30ced1aba1264f0bed806b30b1a81bcdf3f03f9f4398794e": {
"Name": "2234_ServiceA_1",
"EndpointID": "337baff5222025b7d7ea0c5f490a80d1c4f15dbd8b2e5052d0625bb213a407b0",
"MacAddress": "02:42:c0:a8:80:0d",
"IPv4Address": "192.168.128.13/20",
"IPv6Address": ""
},
"5d79cb8e56f7a7789f1860bfc0f48077b326736762c2c13238883bac2a5b40d1": {
"Name": "2234_ConnectToIotService_1",
"EndpointID": "087108a5226caf371c02ae188d17cd96d464b882ff918fd56d382275e6bb57ab",
"MacAddress": "02:42:c0:a8:80:08",
"IPv4Address": "192.168.128.8/20",
"IPv6Address": ""
},
"6524df811e919b3a4f908f286125af45dfd82a3f4aaf9caeb073915bd4bff12e": {
"Name": "2234_ServiceA_1",
"EndpointID": "d73cb225903e5817c1cf31dee48d3262719935b1cc514407c833e63595ecf2b8",
"MacAddress": "02:42:c0:a8:80:05",
"IPv4Address": "192.168.128.5/20",
"IPv6Address": ""
},
"71c2129a451b66fb9ed25946838f3ecef510cdebc66419c0b060cf15446e606a": {
"Name": "2234_ServiceA_1",
"EndpointID": "3806269285d4c60e0de7a3f87ca83c1cb3244578c43905db0e785999e37872d7",
"MacAddress": "02:42:c0:a8:80:03",
"IPv4Address": "192.168.128.3/20",
"IPv6Address": ""
},
"df8d304e89af7b8972a62334ca76c5e402f9f530c356b40d8d0d52ca189dee47": {
"Name": "2234_ServiceA_1",
"EndpointID": "39f9b5afa2eb6cd5eeaeaaccd03d7594c2b3b0b501399de0d8ea3f9a9e4b92fb",
"MacAddress": "02:42:c0:a8:80:04",
"IPv4Address": "192.168.128.4/20",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "main",
"com.docker.compose.project": "2234",
"com.docker.compose.version": "1.27.0"
}
},
{
"Name": "2234_nginx",
"Id": "61d88a21886d9377a8c67b184a4d8a99725ef3b67ec8c2d67dc22de9c271fe96",
"Created": "2022-02-12T14:23:19.2532414Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.144.0/20",
"Gateway": "192.168.144.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"5705f37bb200accee2a1a6a23ba818f89172afab4402809f8f1c6de579437983": {
"Name": "2234_ARAMZLWebAppService_1",
"EndpointID": "b0ea1b5f04ef6ea46332914032dceea21f98deeb161b2c04759e7ec587d1f588",
"MacAddress": "02:42:c0:a8:90:03",
"IPv4Address": "192.168.144.3/20",
"IPv6Address": ""
},
"df8d304e89af7b8972a62334ca76c5e402f9f530c356b40d8d0d52ca189dee47": {
"Name": "2234_web_gateway_1",
"EndpointID": "ecfb032cbd8ab650b7e4cd36c6cfc5035b49a8dc934fc49e4e3a0bf49f5437af",
"MacAddress": "02:42:c0:a8:90:02",
"IPv4Address": "192.168.144.2/20",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "nginx",
"com.docker.compose.project": "2234",
"com.docker.compose.version": "1.27.0"
}
},
{
"Name": "2028970_main",
"Id": "a2cf265e7afddb0691bf2a2b06391a8df0358538cbcc3ffd63823207a3a859ff",
"Created": "2022-02-11T21:43:35.086843314Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.96.0/20",
"Gateway": "192.168.96.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {
"com.docker.compose.network": "main",
"com.docker.compose.project": "2028970",
"com.docker.compose.version": "1.27.0"
}
},
{
"Name": "2028970_nginx",
"Id": "3843388542bc33ef8beb7f81cc599d32b534ade592a8945d62a24ea63aac1d69",
"Created": "2022-02-11T21:43:35.135249579Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.112.0/20",
"Gateway": "192.168.112.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {
"com.docker.compose.network": "nginx",
"com.docker.compose.project": "2028970",
"com.docker.compose.version": "1.27.0"
}
},
{
"Name": "bridge",
"Id": "4fb7977a225db6fa2b8dea7005793a72575cb083b2f997627904a62895cd7f8b",
"Created": "2021-07-29T16:09:49.572103372Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
},
{
"Name": "host",
"Id": "adc73d076a994102aa472eb367600c8096aa914297158b10d4b25cd8fa50ed0c",
"Created": "2021-05-11T20:36:17.195375337Z",
"Scope": "local",
"Driver": "host",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": []
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"5af2e9b7e09b87ef226e2f79a2d97c9f81148a4265230758949717f2dd525c97": {
"Name": "2234_IdsService_1",
"EndpointID": "6ce2fdcb4315fa8368435abaaee1f1c41c4f3a771061992225bb0e49b348e24f",
"MacAddress": "",
"IPv4Address": "",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
},
{
"Name": "none",
"Id": "ee93bca5bbc6e27bce0cab8380e11a4c3b95a4cc17aaff50a1665b5dcb8a0ecd",
"Created": "2021-05-11T20:36:17.184580174Z",
"Scope": "local",
"Driver": "null",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": []
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
Related
The build in docker dns function is broken suddently
I alway lookup the services each other by docker name in my system, things like : "curl http://contianer_name". Initially, All things is fine and It has worked for several months, But it is broken yesterday, Nginx could not bypass the url like http://contianer_name, And I could not curl successfully for the http://container_name in my host machine. What it is happen? :(,,, docker network ls: NETWORK ID NAME DRIVER SCOPE ecbfafa9fccf bridge bridge local b1aac67cfbfa myapp-api_default bridge local 5195101110d3 host host local d90ca5db218d none null local docker network inspect [ { "Name": "myapp-api_default", "Id": "b1aac67cfbfa2923d5ae88a26e8729159f34e1ae083944e385a23047a7fc7237", "Created": "2022-09-28T18:21:57.202490009+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.22.0.0/16", "Gateway": "172.22.0.1" } ] }, "Internal": false, "Attachable": true, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "850c8c091467b7c92aedff5631869ab2f5603ae48ee4a1efb7f18f2f890154ff": { "Name": "app-boot-system-sample", "EndpointID": "1497a7ac8726646f24bf82400d69c56bbcacb689d4423ab54db15af586373179", "MacAddress": "02:42:ac:16:00:05", "IPv4Address": "172.22.0.5/16", "IPv6Address": "" }, "c819074103a5b108d21b836afd1c156036e13f523b44eb5002e13edf48d9f825": { "Name": "sample-tenant-pc", "EndpointID": "d4ef531762a117132cbd40dee729cdf2458061e2444d35fc7968411676329e7b", "MacAddress": "02:42:ac:16:00:04", "IPv4Address": "172.22.0.4/16", "IPv6Address": "" }, "d04e0c550c95da196844c160ca9b9f80f99e3536f92da55d6e9f18533a381802": { "Name": "sample-event-pc", "EndpointID": "71bb31e965df8f47cfcc32685594803496bf77ad396854b5dc57851467f99996", "MacAddress": "02:42:ac:16:00:07", "IPv4Address": "172.22.0.7/16", "IPv6Address": "" }, "ee6589ced2f5080b9f3641104262f430da8f37e1278f094f78a45e2414a607f4": { "Name": "app-boot-redis-sample", "EndpointID": "be41952c5709d7a843b9b2ce3276bd7ac8e951ab653ba478d3a8f7cf7fe9599a", "MacAddress": "02:42:ac:16:00:03", "IPv4Address": "172.22.0.3/16", "IPv6Address": "" }, "fd9196fc0fee67de364d6be37581e4fd9827b2983a332995269af78817828bbd": { "Name": "sample-org-pc", "EndpointID": "a0fd805ee5705533f58b7f0e3f1cbdb0a20abc1a01057bd23a2a5161d0c5181c", "MacAddress": "02:42:ac:16:00:02", "IPv4Address": "172.22.0.2/16", "IPv6Address": "" } }, "Options": {}, "Labels": { "com.docker.compose.network": "myapp-api_default", "com.docker.compose.project": "myapp-api", "com.docker.compose.version": "1.26.2" } } ] Docker compose defined as below in the project sample-tenant-pc: version: '2.4' services: sample-tenant-pc: build: context: . restart: always container_name: sample-tenant-pc image: sample-tenant-pc ports: - 9001:80 networks: - myapp-api_default networks: myapp-api_default: external: false name: myapp-api_default
How can I connect one docker container to another via the default bridge network?
I have a python 3.6 app running inside a docker container (linux python3.6 base image), and this app needs to access another container with a redis instance on it. I have both containers running on the default bridge network, and I have configured the first container to point to the second using the second container's IPv4Address: CELERY_RESULT_BACKEND = redis://172.17.0.3:6379/0 According to the tutorials on docker, this is all you need to connect one container to another when they're running on the same host machine(with no firewalls etc). However, I keep getting a [Errno 111] Connection refused when I try to connect to the redis container. I have checked that the ICC is enabled, and my default bridge network looks like this: [ { "Name": "bridge", "Id": "fda5906e0a6009a5a7dd8839f4d85cdc8de15db34481b7ef15ce66f4343b2f63", "Created": "2021-03-24T07:54:17.8315909Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "38beb0863d86dab0f014ef9f1ad85f02efa7fb96520455df6f6ea6b5519f60cc": { "Name": "local_redis", "EndpointID": "74f510467dba138f10e1662830060a05ee192c368b32844af73eb4e865fc7182", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }, "f314393b25019c8c3084b8cf8465284d5a45c2f48c9aa5c411343e6a5f833c62": { "Name": "rabbitmq", "EndpointID": "a4886c398708d5279a8bf0de9dbd8eadd10dd320120243a2ca8c26e0e0c20e16", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ] Any help would be much appreciated.
Docker: Can't remove macvlan configuration network
Using portainer, I created a macvlan configuration network. Now, I want to remove this network. However, for some reason, I can't. I do receive the following error msg: Error response from daemon: error while removing network: configuration network "my_macvlan_config" is in use. The weird thing is that I don't think that the network is in use. There is no container attached to it. When inspecting the network, I get the following results: ~$ sudo docker network inspect my_macvlan_config [ { "Name": "my_macvlan_config", "Id": "5d95270684516484632c4505e15ba8253bbe8d780b2c41a84a07fbbe09d7a9b6", "Created": "2020-05-18T20:59:03.472260896+02:00", "Scope": "local", "Driver": "null", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "192.168.13.0/24", "IPRange": "192.168.13.200/29", "Gateway": "192.168.13.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": true, "Containers": {}, "Options": { "parent": "eth0" }, "Labels": {} } ] Docker itself is running on my Synology Diskstation, fwiw. EDIT: There's another network called macvlan that is connected to my_macvlan_config. ~$ sudo docker network inspect macvlan [ { "Name": "macvlan", "Id": "8a831afa776475b01ca240f4b6b2434c820b8a03910b402760e3cd988e7ddb5c", "Created": "2020-05-23T23:11:17.738229138+02:00", "Scope": "local", "Driver": "macvlan", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "192.168.13.0/24", "IPRange": "192.168.13.210/29", "Gateway": "192.168.13.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "macvlan_config" }, "ConfigOnly": false, "Containers": { "6f025749fe99a22fa3729bebfa72d6329b363fe8f6589d9147d0d58a9934dd42": { "Name": "tvheadend", "EndpointID": "bc827cb2fddc4374fde7634534efd0c8c110af5a70aa9b16a319b770dfe7a0f2", "MacAddress": "02:42:c0:a8:0d:d3", "IPv4Address": "192.168.13.211/24", "IPv6Address": "" } }, "Options": { "parent": "eth0" }, "Labels": {} } ] And there's one more network, which is apparently unrelated. ~$ sudo docker network inspect macvlan_config [ { "Name": "macvlan_config", "Id": "644a15c6b9e653ec3f48c4a2e290f996b41361170d5ab63053b87a301168345f", "Created": "2020-05-23T23:10:54.880348491+02:00", "Scope": "local", "Driver": "null", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "192.168.13.0/24", "IPRange": "192.168.13.210/29", "Gateway": "192.168.13.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": true, "Containers": {}, "Options": { "parent": "eth0" }, "Labels": {} } ] I then removed the tvheadend container. I was then able to delete all networks but my_macvlan_config.
How to use docker hostname when running a container
I'm runnig RabbitMQ in docker >docker run -d --hostname my-rabbit --name some-rabbit --rm --network my-bridge rabbitmq My container name is some-rabbit and my hostname is my-rabbit The container is connected to my-bridge network My app is also connected to my-bridge network docker network inspect my-bridge produces: [ { "Name": "my-bridge", "Id": "c996f5318b2b3ff907b6680e41c4551f184f2c43b0df43fd6916fa8d1707e427", "Created": "2018-12-26T19:40:46.6982856Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [ { "Subnet": "172.21.0.0/16", "Gateway": "172.21.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "98d81ba991febbc9dc0775effc79a2b083f62fe563aad3ce146e56bab5b09f4c": { "Name": "some-rabbit", "EndpointID": "acb3da3e91d655a3ed245fa3938edd681318129e514b83db07e1b4efd4f2bfc2", "MacAddress": "02:42:ac:15:00:02", "IPv4Address": "172.21.0.2/16", "IPv6Address": "" }, "9fdf456e352e932b13530223f736028f357e63ead5ace042a13200f6d5744d62": { "Name": "dockercompose8897046891659778892_publisher_1", "EndpointID": "f45ba7f9c7832d3514d22ddf29bc19f1e74529cb371b335542c9eb54469fe7a4", "MacAddress": "02:42:ac:15:00:04", "IPv4Address": "172.21.0.4/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ] docker inspect some-rabbit produces: ... "Config": { "Hostname": "my-rabbit", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "25672/tcp": {}, "4369/tcp": {}, "5671/tcp": {}, "5672/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/lib/rabbitmq/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.10", "RABBITMQ_LOGS=-", "RABBITMQ_SASL_LOGS=-", "RABBITMQ_GPG_KEY=0A9AF2115F4687BD29803A206B73A36E6026DFCA", "RABBITMQ_VERSION=3.7.8", "RABBITMQ_GITHUB_TAG=v3.7.8", "RABBITMQ_DEBIAN_VERSION=3.7.8-1", "LANG=C.UTF-8", "HOME=/var/lib/rabbitmq" ], "Cmd": [ "rabbitmq-server" ], "ArgsEscaped": true, "Image": "rabbitmq", "Volumes": { "/var/lib/rabbitmq": {} }, "WorkingDir": "", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": {} }, "NetworkSettings": { "Bridge": "", "SandboxID": "bac2e155323c1ec94e145a37f45f8bc0d32e28a2b363cb1c9f3d4ed922a91a56", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "25672/tcp": null, "4369/tcp": null, "5671/tcp": null, "5672/tcp": null }, "SandboxKey": "/var/run/docker/netns/bac2e155323c", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "my-bridge": { "IPAMConfig": null, "Links": null, "Aliases": [ "98d81ba991fe" ], "NetworkID": "c996f5318b2b3ff907b6680e41c4551f184f2c43b0df43fd6916fa8d1707e427", "EndpointID": "acb3da3e91d655a3ed245fa3938edd681318129e514b83db07e1b4efd4f2bfc2", "Gateway": "172.21.0.1", "IPAddress": "172.21.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:15:00:02", "DriverOpts": null } } } } ] Concluding: Both rabbitmq and my app are running in the same network RabbitMQ has a custom hostname my-rabbit which can be observed when inspecting the container: "Hostname": "my-rabbit" However when my app is trying to reach RabbitMQ at address my-rabbit, connection fails. Only if I use the container name as the address (some-rabbit) it works. Is my understanding of --hostname wrong or am I using it wrong? When is it useful to use custom --hostname?
Hostname is only visible to the application inside that same container. Docker's embedded DNS will not resolve container hostnames. What you can resolve with docker's DNS are: container name container id network alias for a container (including the service name in a compose file)
What IP address to use to connect to container in network?
[ { "Name": "composer_default", "Id": "1b06e8bd3c547c739285284f89d416b6bae6cad8d8a5437659cc2877136c5e8f", "Created": "2018-05-25T06:42:35.269643488Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.18.0.0/16", "Gateway": "172.18.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "1963ad6763c63f3e4dd15b0a4717ddee5c2fe39dad90edbd75c4a0c4f412439b": { "Name": "orderer.example.com", "EndpointID": "a34529bb554dd0a7f3ad706cf95536112774b209619364dd98f7edbb5317b150", "MacAddress": "02:42:ac:12:00:03", "IPv4Address": "172.18.0.3/16", "IPv6Address": "" }, "46237b2a21b2a2dbb513ccea7e93793538bcdeaf583e82911c2451f7ee109faf": { "Name": "couchdb", "EndpointID": "398a01a0f85cf91ddb23933ded579597263135cbe5b027a73d9bbe374837a06f", "MacAddress": "02:42:ac:12:00:04", "IPv4Address": "172.18.0.4/16", "IPv6Address": "" }, "5baee4bb30d087b0d622954228be91509124f632a81774fb382fe0e80111d32b": { "Name": "ca.org1.example.com", "EndpointID": "a458f59f8d3fa2600f6eb933ee685bffc08ac83cd793ad707f9188b1a07fb6a9", "MacAddress": "02:42:ac:12:00:02", "IPv4Address": "172.18.0.2/16", "IPv6Address": "" }, "651d6d2878104cc496b0bafd6466b70d8a45ef462cc06130e93e0a50214d1f99": { "Name": "peer0.org1.example.com", "EndpointID": "9e9a7c2c3164d6258e5bd3231376772703fe2d621978e0760e44569fc3c8c567", "MacAddress": "02:42:ac:12:00:05", "IPv4Address": "172.18.0.5/16", "IPv6Address": "" }, "da6a8ade513c4fb9b1a351f42e0a06f2e26f0eb471fa08832aa3863285e2f384": { "Name": "dev-peer0.org1.example.com-usps-imts-network-0.0.2", "EndpointID": "0f73549d1c16abb13fe1a2d1a1a175e6161ad3d155064033654a436669468b9e", "MacAddress": "02:42:ac:12:00:06", "IPv4Address": "172.18.0.6/16", "IPv6Address": "" } }, "Options": {}, "Labels": {} } ] I have another Node.js app in a container that I will add to this composer_default network. orderer.example.com is also in this network in its own container. When Node.js app was outside of container, I was previously doing grpc://localhost:7050 to connect. Now that it is in a container, grpc://<WHAT-IP-SHOULD-I-USE>:7050? I tried the container name grpc://orderer.example.com:7050, as well the network gateway grpc://172.18.0.1:7050, and am unable to connect.
Container name or IP should work so http:localhost:7050 => http://orderer.example.com:7050 or http://172.18.0.3:7050. { "name":"hlfv1", "x-type":"hlfv1", "x-commitTimeout":300, "version":"1.0.0", "client":{ "organization":"Org1", "connection":{ "timeout":{ "peer":{ "endorser":"300", "eventHub":"300", "eventReg":"300" }, "orderer":"300" } } }, "channels":{ "composerchannel":{ "orderers":[ "orderer.example.com" ], "peers":{ "peer0.org1.example.com":{ } } } }, "organizations":{ "Org1":{ "mspid":"Org1MSP", "peers":[ "peer0.org1.example.com" ], "certificateAuthorities":[ "ca.org1.example.com" ] } }, "orderers":{ "orderer.example.com":{ "url":"grpc://orderer.example.com:7050" } }, "peers":{ "peer0.org1.example.com":{ "url":"grpc://peer0.org1.example.com:7051", "eventUrl":"grpc://peer0.org1.example.com:7053" } }, "certificateAuthorities":{ "ca.org1.example.com":{ "url":"http://ca.org1.example.com:7054", "caName":"ca.org1.example.com" } } }