This post was most recently updated on April 29th, 2022.
2 min read.Here is another fun one for the books! In this article, I will explain how to fix a problem with the Azure IoT Edge dev simulator, when it fails to start due to an underlying problem with Docker not having access to your defined ports. This will probably happen to one of the ports used by the Edge Hub system module by default – 5671, 8883, or 443.
Problem
So, when you’re trying to run an Azure IoT Edge solution in the simulator, you get an error like this in the terminal, and the simulator refuses to start:
ERROR: for edgeHubDev Cannot start service edgeHubDev: Ports are not available: listen tcp 0.0.0.0:8883: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
What gives?
Reason
Something’s hogging the ports your Azure IoT Edge simulator (a fancy wrapper on top of Docker) wants to use. It can’t do much when it can’t listen to the ports, so it fails to start.
Okay, another one that should be a simple fix! We’ll just need to figure out a way to free the ports, right?
Well, it turns out that it’s not that easy. Shutting down Docker and Visual Studio Code doesn’t actually resolve the issue, and running netstat shows the port is not actually in use. But the problem persists.
So, what do?
Solution
Luckily, the solution shouldn’t be that bad. Let’s see…
As usual, I’m documenting the things that I tried (since they should’ve/could’ve helped) and the actual solution :)
Time needed: 10 minutes
How to fix “Cannot start service edgeHubDev: Ports are not available”
-
Theoretically speaking, there was a decent enough chance that restarting the applications/services that might’ve been using the port (in this case, Visual Studio Code, the IoT Edge Simulator, and Docker) should’ve helped – but it didn’t.
Still, it might work for you. - Verify the ports you’re using
Okay, so maybe the error message is right – verify that your port mappings make sense. This is done in the createOptions of your modules (which are Docker containers). Generally speaking, for your Azure IoT Edge Hub Module ($edgeHub), you should see something like this:
"edgeHub": {
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.2",
"createOptions": {
"HostConfig": {
"PortBindings": {
"5671/tcp": [
{
"HostPort": "5671"
}
],
"8883/tcp": [
{
"HostPort": "8883"
}
],
"443/tcp": [
{
"HostPort": "443"
}
]
}
}
}
}
}
If your configuration is something very different, you might have an issue. - Stop and start the Windows NAT driver
Fire up your command prompt, and run the following 2 commands:
net stop winnat
net start winnat
Then retry with the simulator! - Reboot your machine
If nothing else works, restart your machine, and that will work.
And if it won’t, no idea. To be fair, I’ve never ended on this step, so no idea what to do now.
Well, no matter whether you’re encountering this with Docker or with IoT Edge Simulator, I hope this helped. If it didn’t, let me know in the comments -section below – I’d love to know how widespread an issue this is, and if there are other ways to fix it!
References
- https://stackoverflow.com/questions/57891647/port-issue-with-docker-for-windows
- https://social.technet.microsoft.com/Forums/lync/en-US/50c60014-9c7d-4fc1-a1c9-a195334a34b2/what-is-the-winnat-service?forum=winserveressentials
- How to export the whole SSL (or TLS) certificate chain based on the original using PowerShell? - September 17, 2024
- How to solve keyboard shortcuts not working in Google Chrome on Windows? - September 10, 2024
- Search (and secretly, sync) broken in OneNote? A quick fix! - September 3, 2024