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": {}
}
]
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.
Previous using Docker 17.05, I was able to create overlay network with subnet 10.0.7.0/24 and then I was able to create a container with IP 10.0.7.2.
Now I am using Docker 18.03, I am able to create overlay network with subnet 10.0.7.0/24. But I am not able to create a container with IP 10.0.7.2.
I know that 10.0.7.1 is gateway IP. But what is 10.0.7.2 is being used for in new Docker(18.03).
please, can anybody explain why this happening?
On Docker 18.03,
mynet is my overlay network
> docker inspect mynet
[
{
"Name": "mynet",
"Id": "4lq0j7thvyb8dkwt0zbbvgski",
"Created": "2018-03-29T09:27:41.369349452Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.7.0/24",
"Gateway": "10.0.7.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": null,
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4102"
},
"Labels": null
}
]
docker run is showing this error:
> docker run -dit --name mycon --network mynet --ip 10.0.7.2 ubuntu:16.04
caebeda51357d8e53f11fb765c8b4a65bd6c37d6746dbbdd1b4b8be7e6235a44
docker: Error response from daemon: attaching to network failed, make sure your network options are correct and check manager logs: context deadline exceeded.
Thanks in advance.
Check if the swarm node is set to availability=drain.
The issue is documented here
Otherwise, in 18.03, I have not faced this issue.
The following network works for me if availability is set to active, and I hit your issue if it is set to drain.
docker inspect ovr2 [
{
"Name": "ovr2",
"Id": "28a5i9gcnys642u059ltfcjut",
"Created": "2018-11-20T16:26:07.458744293Z",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.7.0/24",
"Gateway": "10.0.7.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": null,
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4097"
},
"Labels": null
} ]
To avoid conflicts, I want to use a defined range of subnets for the docker0 bridge and all interfaces dynamically created by the docker deamon when a new container is started.
After a quick look in the docker documentation I found the promising fixed-cidr option. I added this option to my daemon.json. My configuration looks as follows:
/etc/docker/daemon.json
{
"bip": "192.168.89.1/22",
"fixed-cidr": "192.168.89.2/24"
}
after restarting the docker deamon the configuration looks promising:
docker inspect bridge
[
{
"Name": "bridge",
"Id": "365e0d373bcfc82bc73c623d680dcaee773e247f631e5b2324e3b63401bcf6fd",
"Created": "2018-03-19T09:59:22.20439309+01:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.89.1/22",
"IPRange": "192.168.89.0/24",
"Gateway": "192.168.89.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": {}
}
]
But for some reason, when I create a new network:
docker network create test-network
it gets a new address from default IP range:
docker inspect test-network
[
{
"Name": "test-network",
"Id": "bf0f6baa8239c73a9524f8a77035bc2be18a67ad4d0d2ba4f73b3d175f5315b3",
"Created": "2018-03-19T10:31:24.450183553+01:00",
"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": {},
"Options": {},
"Labels": {}
}
]
For now, I have a temporary solutation. I'll simply define a custom subnet in my docker-compose.yml
yaml
networks:
default:
ipam:
config:
- subnet: 192.168.89.2/24
But this leads to further problems as a cannot start the project multiple times on the same hosts, because of network conflicts.
Does anyone know where the problem is?
Edit:
It seems to be a missing feature in docker. Github Issue
Fortunately this feature has been committed to master branch some days ago: Committed feature
In new docker releases there is the default-address-pools option.
Network options in /etc/docker/daemon.json only work for the default docker0 bridge.
You can specify network options when creating new networks, see: https://docs.docker.com/engine/reference/commandline/network_create/
I am not able to connect to docker container when there is network/ip change from office to home. But the same works with localhost or 127.0.0.1
I am connecting to VPN to connect to database.
root#1c970ed5cd64:/etc# curl
http://localhost:8090/admin/health_check/all
{“health”:“passed”}root#1c970ed5cd64:/etc# curl
http://192.168.0.103:8090/admin/health_check/all curl: (7) Failed to
connect to 192.168.0.103 port 8090: Connection refused
When i install docker again everything works fine.
I have created docker-machine with external virtual switch pointing to wifi and ran the container with the host ip.
The same working on diffferent machine. Below i have not seen DOCKER_HOST ip when i do inspect the network
PS C:\Users\KH1046> docker network inspect -v 6fad6cc07d43 [
{
"Name": "bridge",
"Id": "6fad6cc07d43f576ca4921559346a4919ea6ffd8172726adccb31b4ffaa23acd",
"Created": "2017-08-12T18:07:33.2239814Z",
"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": {
"b81f7e258650a150c72ab255c35d321a9a01aea090c6e03ec38de6c373ebfe46": {
"Name": "konymobilefabric_tomcat",
"EndpointID": "ae18e2a9874ab56967d06450ea7b26c7f47c408ff173c1610ac7bd0b322e24d3",
"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": {}
} ]
Thanks,
Kusuma