Skip to content

Latest commit

 

History

History
59 lines (35 loc) · 2.32 KB

File metadata and controls

59 lines (35 loc) · 2.32 KB

This example is deprecated. Please refere to the new .NET 6 example.

Quick Start to build an ASP.NET Core 3.0 WebAPI with Profiler (Part II)

In the last post, we walked through how to build an application with Application Insights Profiler on locally. In this post, we are going to containerize the app and get it run inside a container.

Prerequisites

  1. Finish part I to have a working application with Profiler on.
  2. Docker Desktop on Windows.

Get started

Create a Dockerfile for the application

Since we already have a working project, just follow the dockerfile example from the docker documentation with the following tweaks:

  1. For ASP.NET Core 3.0, update the base images.

    Find the base images for ASP.NET Core on the dockerhub.

    Specifically, we need an SDK image and a ASP.NET Core runtime image and update the image names in the dockerfile.

    At the moment, actually the changes required are change the tags to 3.0 from 2.2 for both build-env and for the runtime image.

  2. Set the environment variable to provide instrumentation for release build of the application:

    ENV APPLICATIONINSIGHTS_CONNECTION_STRING="YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING"
  3. Update the entry point toward the end of the file to pick up the proper assembly.

A full example could be found here.

Build and start the container

Here's some shorthands for building and running the container:

docker build -t quickstart30:0.0.1 .
docker run -p 8080:80 --name aiprofiler-quickstart quickstart30:0.0.1

Let's generate traffic for the following endpoint this time:

http://localhost:8080/weatherforecast

And as we did before, we will wait for 2 minutes to let the data ingest after the profiling session.

You will be able to get the same result as it is running locally.

Delete the container after the testing

docker container rm aiprofiler-quickstart -f