This example is deprecated. Please refere to the new .NET 6 example.
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.
- Finish part I to have a working application with Profiler on.
- Docker Desktop on Windows.
Since we already have a working project, just follow the dockerfile example from the docker documentation with the following tweaks:
-
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
from2.2
for bothbuild-env
and for the runtime image. -
Set the environment variable to provide instrumentation for release build of the application:
ENV APPLICATIONINSIGHTS_CONNECTION_STRING="YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING"
-
Update the entry point toward the end of the file to pick up the proper assembly.
A full example could be found here.
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.
docker container rm aiprofiler-quickstart -f