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.
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.
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?
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:
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!
- How to import an Azure DevOps Git repository… From another Azure DevOps organization? - September 27, 2022
- How to fix NU3028 and NU3037 errors in Azure DevOps builds? - September 20, 2022
- How to kill the process causing the “MSB3021 Unable to copy file — The process cannot access the file because it is being used by another process.” error? - September 13, 2022