VS Code devcontainer for Azure IoT Edge

Vitaliy Slepakov
2 min readAug 15, 2019

There are several Tools when it comes to Azure IoT Edge development. Most of them require you to install stuff on your machine. They allow you to debug your modules and simulate IoT Edge devices. Some of those tools use Containers.

IoT Edge runtime in a container provides a complete runtime BUT your modules still run outside this container.

IoT Edge device container on the other hand is a complete IoT Edge device including the IoT Edge runtime and a container engine. It can be used for remote debugging and also for running large number of simulated IoT Edge devices e.g. for load or integration testing as part of a CI/CD pipeline. This approach is quite good but you still need to install a few VS Code extensions for the actual development and also to configure everything.

Then I learnt about Remote Containers for VS Code and felt like I really needed to try it out. That is when I got the idea to take IoT Edge device container approach one step further and to create a devcontainer with everything included (IoT Edge runtime, container engine, VS Code extensions, other tools, etc.) removing the need for having all that natively on my machine. This also allows to have a versioned definition of the IoT Edge development environment which can be shared within a team reducing ramp up time for new developers and ensuring everyone uses the same environment. This helps to avoid “works on my machine” phenomenon. You can find an example in this repo.

So how does it work?

  • You basically start with an empty folder for your new Edge Solution and clone the .devcontainer from this repo into it.
  • Create an .env file inside the .devcontainer directory and define your device connection string for your IoT Edge device like this (NOTE: you should not put your .env file into git repo):
DEVICE_CONNECTION_STRING='HostName=YOUR_IOTHUB.azure-devices.net;DeviceId=YOUR_DEVICEID;SharedAccessKey=YOUR_SAS_KEY'
  • If needed, extend the Dockefile to include tools and extensions that you need.
  • Open the Edge Solution folder you’ve just created in VS Code and using the Remote Containers extension Reopen Folder in Container. This will reload VS Code and connect your workspace to the IoT Edge container. It will also automatically install several extensions so you can use them while developing inside container. The extensions are (feel free yo add your own):
ms-azuretools.vscode-docker
vsciot-vscode.azure-iot-edge
vsciot-vscode.azure-iot-toolkit
ms-vscode.azurecli

Now you can start developing and testing your Edge Solution inside the devcontainer.

What’s left to do?

Depending on what kind of modules you want to create, extend the Dockerfile to use another base image (e.g. dotnet) or just use apt-get to install what you need (tools and frameworks).

What’s next?

I’ll keep working on improving developer experience adding tools, creating new base images etc. I appreciate pull requests.

--

--