title | description | author | manager | ms.service | services | ms.topic | ms.custom | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|
Deploy a custom Device Simulation image - Azure| Microsoft Docs |
In this how-to guide, you learn how to deploy a custom Docker image of the Device Simulation solution to Azure. |
dominicbetts |
timlt |
iot-accelerators |
iot-accelerators |
conceptual |
mvc |
11/06/2018 |
dobett |
You can modify the Device Simulation solution to add custom features. For example, the Serialize telemetry using Protocol Buffers article shows you how to add a custom device to the solution that uses Protocol Buffers (Protobuf) to send telemetry. After you've tested your changes locally, the next step is to deploy your changes to your Device Simulation instance in Azure. To complete this task, you need to create and deploy a Docker image that contains your modified service.
The steps in this how-to-guide show you how to:
- Prepare a development environment
- Generate a new Docker image
- Configure Device Simulation to use your new Docker image
- Run a simulation using the new image
To complete the steps in this how-to guide, you need:
- A deployed Device Simulation instance.
- Docker. Download the Docker Community Edition for your platform.
- A Docker Hub account where you can upload your Docker images. In your Docker Hub account, create a public repository called device-simulation.
- A modified and tested Device Simulation solution on your local machine. For example, you can modify the solution to Serialize telemetry using Protocol Buffers.
- A shell that can run SSH. If you install Git For Windows, you can use the bash shell that's part of th installation. You can also use your Azure Cloud Shell.
The instructions in this article assume you're using Windows. If you're using another operating system, you may need to adjust some of the file paths and commands to suit your environment.
To deploy your own changes to the Device Simulation service, you need to edit the build and deployment scripts in scripts\docker folder to upload the containers to your docker-hub account
Modify the Docker build.cmd, publish.cmd, and run.cmd scripts in the scripts\docker folder with your Docker Hub repository information. These steps assume you created a public repository called device-simulation:
DOCKER_IMAGE={your-docker-hub-username}/device-simulation
Update the docker-compose.yml file as follows:
image: {your-docker-hub-username}/device-simulation
If you added any new device model files, you need to explicitly include them in the solution. Add an entry to the services/services.csproj for each additional file to include. For example, if you completed the Serialize telemetry using Protocol Buffers how-to, add the following entries:
<None Update="data\devicemodels\assettracker-01.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\devicemodels\scripts\assettracker-01-state.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Publish the new Docker image to Docker Hub using your docker-hub account:
-
Open a command prompt and navigate to your local copy of the device simulation repository.
-
Navigate to the docker folder:
cd scripts\docker
-
Run the following command to build the Docker image:
build.cmd
-
Run the following command to publish the Docker image to your Docker Hub repository. Sign in to Docker with your Docker Hub credentials:
docker login publish.cmd
[!INCLUDE iot-solution-accelerators-access-vm]
To update the Device Simulation container to use your custom image, complete the following steps:
-
Use SSH to connect to the virtual machine hosting your Device Simulation instance. Use the IP address and password you made a note of in the previous section:
ssh azureuser@{your vm ip address}
-
Navigate to the /app directory:
cd /app
-
Edit the docker-compose.yml file:
sudo nano docker-compose.yml
Modify the image to point the custom device-simulation image you uploaded to your Docker Hub repository:
image: {your-docker-hub-username}/device-simulation
Save your changes.
-
Run the following command to restart the microservices:
sudo start.sh
You can now run a simulation using your customized Device Simulation solution:
-
Launch your Device Simulation web UI from Microsoft Azure IoT Solution Accelerators.
-
Use the web UI to configure and run a simulation. If you previously completed Serialize telemetry using Protocol Buffers, you can use your custom device model.
Now you've learned how to deploy a custom Device Simulation image, you may want to learn how to Use an existing IoT hub with the Device Simulation solution accelerator.