Building an Azure Event Grid app. Part 3: Turning the publisher app into a Docker image.

Why do I want my publisher app to be a Docker image? Because I’d potentially like to be able to run the app from different environments and/or have other people run the app from their environments. Not having to rebuild or distribute the binaries would make it easier and I can be more certain that it will “just work”.

How to take my code (.NET Core in my example but again could be pretty much anything) and containerize it? I edited my app using Visual Studio Code and that made the process very easy.

  1. Make sure you’ve got the Docker extension installed in VS Code.
  2. Get VS Code to generate the Dockerfile for you by just answering some simple questions.
  3. Get VS Code to build the image for you.

That’s it. Very straightforward and now I have a Docker image for my app, run docker images and see your new image, or use the Docker explorer in VS Code for a UI equivalent.

Now I can run docker run <imagename> and pass in the same arguments as discussed in part 1.

But that’s only useful on my dev box. What I can now do is push the image to a repository so that I, or someone else, can pull down the image and run it on another environment. The obvious repository options for me are DockerHub and Azure Container Registry. In this example I’ll push to DockerHub as I want it to be easily publicly available:

  1. Create a DockerHub login if you don’t have one.
  2. Login to Docker at the command line:
 docker login
  1. Build the container with a suitable tag (the prefix being your DockerHub id)
 docker build -t gdavi/alarms-iot-simulator .
  1. Push the image to the repository:
 docker push gdavi/alarms-iot-simulator

You should then have your image in the repository. Mine is at https://hub.docker.com/r/gdavi/alarms-iot-simulator/

Now you can perform a docker pull and have the image on another environment quickly, and ready to run as soon as it’s downloaded.

Cheers,
Giles

Building an Azure Event Grid app. Part 1: Event Grid Topic and a .NET Core custom app event publisher.

Building an Azure Event Grid app. Part 2: Adding a Logic App subscriber to the Event Grid Topic.

Building an Azure Event Grid app. Part 3: Turning the publisher app into a Docker image.

Building an Azure Event Grid app. Part 4: Adding a Service Principal to the Event Grid Topic.

Building an Azure Event Grid app. Part 5: CI and pushing to DockerHub with VSTS.