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.
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
# Use the correct tagged version for your application's targeted runtime. See https://hub.docker.com/_/microsoft-dotnet-aspnet/
FROM mcr.microsoft.com/dotnet/aspnet:6.0
# 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 \
&& rm -rf /var/lib/apt/lists/*
# 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
# This example uses .NET 6.0. For other versions, see https://hub.docker.com/_/microsoft-dotnet-sdk/
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base
# Build your application
WORKDIR /src
RUN dotnet new mvc -o YOUR_APP_NAME
RUN dotnet publish -c Release -o /app ./YOUR_APP_NAME
# The runtime tag version should match the SDK tag version
FROM mcr.microsoft.com/dotnet/aspnet:6.0 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 mcr.microsoft.com/dotnet/framework/aspnet
# Publish your application.
COPY your app to be published /inetpub/wwwroot
# Download the New Relic .NET agent installer
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;\
Invoke-WebRequest "https://download.newrelic.com/dot_net_agent/latest_release/NewRelicDotNetAgent_x64.msi"\
-UseBasicParsing -OutFile "NewRelicDotNetAgent_x64.msi"
# Install the New Relic .NET agent
RUN Start-Process -Wait -FilePath msiexec -ArgumentList /i, "NewRelicDotNetAgent_x64.msi", /qn,\
NR_LICENSE_KEY=YOUR_LICENSE_KEY
# Remove the New Relic .NET agent installer
RUN Remove-Item "NewRelicDotNetAgent_x64.msi"
# 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
# Download the New Relic .NET agent installer
RUN powershell.exe [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;\
Invoke-WebRequest "https://download.newrelic.com/dot_net_agent/latest_release/NewRelicDotNetAgent_x64.msi"\
-UseBasicParsing -OutFile "NewRelicDotNetAgent_x64.msi"
# Install the New Relic .NET agent
RUN powershell.exe Start-Process -Wait -FilePath msiexec -ArgumentList /i, "NewRelicDotNetAgent_x64.msi", /qn,\
NR_LICENSE_KEY=YOUR_LICENSE_KEY
# Remove the New Relic .NET agent installer
RUN powershell.exe Remove-Item "NewRelicDotNetAgent_x64.msi"
# Enable the agent
ENV CORECLR_ENABLE_PROFILING=1
# Set your application name
ENV NEW_RELIC_APP_NAME=YOUR_APP_NAME
# windows/servercore images may not include the .NET Core SDK or runtime
RUN dotnet sdk/runtime installer
WORKDIR /app
ENTRYPOINT ["dotnet", ".\\YOUR_APP_NAME.dll"]