Azure / iot-edge-v1

Azure IoT Edge
http://azure.github.io/iot-edge/
Other
524 stars 258 forks source link

[V2] Accessing LAN from inside docker container #637

Closed msot99 closed 6 years ago

msot99 commented 6 years ago

OS: Ubuntu 16.04 Arch: AMD64 Version: 2 Docker: Linux Version: 18.06.0-dev (I think)

Okay!

I have built a custom module that is supposed to connect to another machine on my network that is hosting a SOAP server. It streams data the server to the hub. My only issue is I can't get the module to connect to the SOAP server. I know that the docker containers operate on their own network, and that I need to open some port for my module to connect to the server. Here is what I have\understand.

The port I am trying to access on the other machine is port 2011 via http. Following this issue, https://github.com/Azure/iot-edge-v1/issues/561, I am trying to open up the port for my custom container to get the information off my LAN.

"createOptions": { "ExposedPorts": { "2011/http": {} }, "HostConfig": { "PortBindings": { "2011/http": [ { "HostPort": "2011" } ] } }

When I run with these create options, I get the error,

[Edge] Start deployment to [FB-IOT-STREAMING-DEVICE] [Edge] Deployment failed. Error: Request failed with status code 400 [Edge] ErrorCode:ArgumentInvalid;Provided json is not a valid 'tags' or 'properties' object: arrays are not supported.

There is also another issue that is similar. In both of these there is said a way to make the container not connect to the docker network, but I can not find any documentation anywhere for how to do that. Or any documentation on the createOptions!

Any help would be greatly appreciated!

damonbarry commented 6 years ago

It should "just work". You don't need to expose ports from your container because it isn't acting as the server; it's the client. IoT Edge instructs docker to set up all modules on their own network together (named azure-iot-edge) but docker bridges it to your local network, so it should be able to reach other local devices and internet endpoints.

For example, I have two Raspberry Pis on my desk, pi1 and pi2. pi1 is running Azure IoT Edge. Assuming pi2 has IP address 172.168.0.2, I can run the following commands from pi1:

pi@pi1:~ $ docker run --rm -it --network azure-iot-edge ubuntu
root@794cf6ec95b4:/$ apt-get update && apt-get install --yes iputils-ping
root@794cf6ec95b4:/$ ping -c 3 172.168.0.2

Output of ping:

PING 172.168.0.2 (172.168.0.2) 56(84) bytes of data.
64 bytes from 172.168.0.2: icmp_seq=1 ttl=63 time=1.14 ms
64 bytes from 172.168.0.2: icmp_seq=2 ttl=63 time=0.894 ms
64 bytes from 172.168.0.2: icmp_seq=3 ttl=63 time=0.874 ms

--- 172.168.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.874/0.969/1.140/0.123 ms

Are you able to reproduce this? Do you perhaps have other network settings or firewalls getting in the way?

damonbarry commented 6 years ago

@jessebean I noticed this in your description:

[Edge] ErrorCode:ArgumentInvalid;Provided json is not a valid 'tags' or 'properties' object: arrays are not supported.

That error is happening because you inserted "createOptions" in your deployment as JSON. You need to serialize the JSON to a string instead. For example, the default "createOptions" for edgeHub looks like this:

"createOptions":"{\"HostConfig\":{\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}],\"5671/tcp\":[{\"HostPort\":\"5671\"}]}}}"

Can your module talk to your SOAP server if you don't specify "createOptions"? If not, what's the error?

msot99 commented 6 years ago

@damonbarry Serializing the JSON worked fixed that deployment issue! I must have missed that earlier!

As for accessing the server, I dug around and realized I was using the computer name and since Docker and my linux box aren't on Active Directory, I needed to use the IP address (facepalm).

Thanks for the help! Everything is working!