In Azure IoT Edge docker containers are the deployment vehicle for the runtime and custom logic. You define the stack of modules in the deployment configuration through the Azure Portal. If the deployment is submitted the edge agent is grabbing the new deployment configuration and applies the state to the local edge device.

During this process the docker containers will be created on the edge device. This creation process can be modified using the createOptions using the portal (or later the command line) like shown in this screenshot

createOption in the Azure Portal

Docker Api

You can use all container creation options provided by the Docker API. To expose port 8081 to the docker host you enter

1
2
3
4
5
6
7
8
9
10
11
{
"HostConfig": {
"PortBindings": {
"8081/tcp": [
{
"HostPort": "8081"
}
]
}
}
}

Verifying createOptions during Startup

You can docker logs -f edgeAgent to check if the containers created will include the specified createOptions for your deployment. Below you see the output of the port 8081 binding.

1
2017-12-01 11:26:11 [INF] - Executing command: "docker rm socket-module && docker create {\"Env\":[\"EdgeModuleCACertificateFile=/mnt/edgemodule/edge-device-ca.cert.pem\",\"EdgeHubConnectionString=******\"],\"Image\":\"dariuszparys/socketmodule:latest\",\"Labels\":{\"net.azure-devices.edge.owner\":\"Microsoft.Azure.Devices.Edge.Agent\",\"net.azure-devices.edge.normalizedCreateOptions\":\"{\\"HostConfig\\":{\\"PortBindings\\":{\\"8081/tcp\\":[{\\"HostPort\\":\\"8081\\"}]}}}\",\"net.azure-devices.edge.restartPolicy\":\"Always\",\"net.azure-devices.edge.desiredStatus\":\"Running\",\"net.azure-devices.edge.version\":\"1.0\"},\"HostConfig\":{\"Binds\":[\"edgemodule:/mnt/edgemodule:ro\"],\"LogConfig\":{\"Type\":\"json-file\",\"Config\":{\"max-size\":\"10m\"}},\"PortBindings\":{\"8081/tcp\":[{\"HostPort\":\"8081\"}]}},\"NetworkingConfig\":{\"EndpointsConfig\":{\"azure-iot-edge\":{}}}}"

and running docker ps -l will show you that the ports are exposed correctly

1
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a693bdd9755 dariuszparys/socketmodule:latest "dotnet SocketModu..." 2 minutes ago Up 2 minutes 0.0.0.0:8081->8081/tcp socket-module

WebSocket Module

For a complete Azure IoT Edge module using WebSockets and leveraging the port bindings create options you can have a look at this Github repo

https://github.com/dariuszparys/iotedge-websocket-module