• /
  • Log in

Install .NET agent on Docker container

This document provides some samples for how you can configure a Dockerfile to install the New Relic .NET agent. Examples are included for both Windows and Linux containers.

Installing the .NET agent in a Docker container can be performed using the same procedures as a standard .NET agent install for either Windows or Linux. It's just a matter of configuring your Dockerfile to perform the procedure.

Tip

To use .NET or any other agent, as well as the rest of our observability platform, join the New Relic family! Sign up to create your free account in only a few seconds. Then ingest up to 100GB of data for free each month. Forever.

Overview for install of .NET agent on Docker

Requirements include:

  • The agent must be installed on the containers you want to monitor.
  • Install the agent with one of the standard install procedures.
  • Enable the agent by setting the required environment variables as applicable.
  • The .NET agent must be installed and enabled at runtime.

Install for Linux Docker containers

Example Linux Dockerfile

FROM microsoft/dotnet:2.2-aspnetcore-runtime

# Publish your application.
COPY your app to be published /app

# Install the agent
RUN apt-get update && apt-get install -y wget ca-certificates gnupg \
&& echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list \
&& wget https://download.newrelic.com/548C16BF.gpg \
&& apt-key add 548C16BF.gpg \
&& apt-get update \
&& apt-get install -y newrelic-netcore20-agent

# Enable the agent
ENV CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A} \
CORECLR_NEWRELIC_HOME=/usr/local/newrelic-netcore20-agent \
CORECLR_PROFILER_PATH=/usr/local/newrelic-netcore20-agent/libNewRelicProfiler.so \
NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
NEW_RELIC_APP_NAME=YOUR_APP_NAME

WORKDIR /app

ENTRYPOINT ["dotnet", "./YOUR_APP_NAME.dll"]

Example Linux Multi-stage Dockerfile

FROM microsoft/dotnet:2.2-sdk AS base

# Build your application
WORKDIR /src
RUN dotnet new mvc -o YOUR_APP_NAME
RUN dotnet build -c Release -o /app/ ./YOUR_APP_NAME

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS final

# Install the agent
RUN apt-get update && apt-get install -y wget ca-certificates gnupg \
&& echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list \
&& wget https://download.newrelic.com/548C16BF.gpg \
&& apt-key add 548C16BF.gpg \
&& apt-get update \
&& apt-get install -y newrelic-netcore20-agent

# Enable the agent
ENV CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A} \
CORECLR_NEWRELIC_HOME=/usr/local/newrelic-netcore20-agent \
CORECLR_PROFILER_PATH=/usr/local/newrelic-netcore20-agent/libNewRelicProfiler.so \
NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
NEW_RELIC_APP_NAME=YOUR_APP_NAME

WORKDIR /app
COPY --from=base /app .

ENTRYPOINT ["dotnet", "./YOUR_APP_NAME.dll"]

Install for Windows Docker containers

Important

Windows Nano Server images are not supported.

Example Windows Dockerfile for .NET Framework application

FROM microsoft/aspnet

# Publish your application.
COPY your app to be published /inetpub/wwwroot

# Copy the New Relic .NET agent installer
COPY ./NewRelicDotNetAgent_x64.msi /

# Install the agent
RUN powershell.exe Start-Process -Wait -FilePath msiexec -ArgumentList /i,\ 
"C:\NewRelicDotNetAgent_x64.msi",\
/qn,NR_LICENSE_KEY=YOUR_LICENSE_KEY

# Set your application name
ENV NEW_RELIC_APP_NAME=YOUR_APP_NAME

Example Windows Dockerfile for .NET Core application

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Publish your application.
COPY your app to be published /app

# Copy the New Relic .NET agent installer
COPY ./NewRelicDotNetAgent_x64.msi /

# Install the agent
RUN Start-Process -Wait -FilePath msiexec -ArgumentList /i,
"C:\NewRelicDotNetAgent_x64.msi",
/qn, NR_LICENSE_KEY=YOUR_LICENSE_KEY

# Enable the agent
ENV CORECLR_ENABLE_PROFILING=1

# Set your application name
ENV NEW_RELIC_APP_NAME=YOUR_APP_NAME

# windowsservercore images may not include the .NET Core SDK or runtime
RUN dotnet sdk/runtime installer

WORKDIR /app

ENTRYPOINT ["dotnet", ".\\YOUR_APP_NAME.dll"]

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.