Install the .NET Core 2.0 agent with Docker

You can install the New Relic for .NET Core 2.0 agent inside a Microsoft Windows Docker container to monitor your .NET Core 2.0 apps. The .NET Core 2.0 agent is compatible with Docker containers for Windows and Linux.

Verify that you meet the compatibility and requirements for the .NET Core 2.0 agent before you install.

Install for Windows Docker containers

The .NET Core 2.0 agent supports running within a Windows Docker container using a Windows Server Core image, with these restrictions:

  • A default image containing the .NET Core 2.0 SDK is not available, so you must create a custom image that contains the necessary .NET Core 2.0 files.
  • Windows Nano Server is not supported.

To install the .NET Core 2.0 agent for Docker containers on Windows:

1. Prepare your application directory
  1. Install Docker for Windows and configure it to use Windows containers.

  2. Publish your web application locally.

  3. Download the >dotnet-sdk to your local machine, and copy it to your application root.

  4. Download the non-scriptable installer agent zip file from New Relic's download site. In the application root, decompress the .NET Core 2.0 agent into a NewRelic folder.

2. Create a Dockerfile

Instructions for writing a Dockerfile that creates a working container vary depending on your application and environment. This example uses the Microsoft-published Windows Server Core Docker image.

  1. Create the Dockerfile in your application root.

  2. Edit your Dockerfile:

    • Reference the microsoft/windowsservercore Docker image.

    • Define your entry point.

    • Set your working directory.

    • Set these New Relic environment variables:

      CORECLR_ENABLE_PROFILING=1 \
      CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A} \
      CORECLR_NEWRELIC_HOME=C:\\PATH\\TO\\NEWRELIC \
      CORECLR_PROFILER_PATH=C:\\PATH\\TO\\NEWRELIC\\NewRelic.Profiler.dll \
      NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
      NEW_RELIC_APP_NAME=YOUR_APP_NAME
  3. Copy the dotnet-sdk to the image.

  4. Run the dotnet-sdk using the /quiet parameter.

  5. Copy your published application files to the image.

  6. Copy the NewRelic directory to the image.

  7. Set the ASPNETCORE_URLS environment variable to the correct port.

  8. Expose the port referenced by ASPNETCORE_URLS.

Example Windows Dockerfile
FROM microsoft/windowsservercore

ENV CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A} \
CORECLR_NEWRELIC_HOME=C:\\app\\newrelic \
CORECLR_PROFILER_PATH=C:\\app\\newrelic\\NewRelic.Profiler.dll \
NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
NEW_RELIC_APP_NAME=YOUR_APP_NAME

WORKDIR /app

ARG core=dotnet-sdk-2.0.0-win-gs-x64.exe
COPY $core .
RUN dotnet-sdk-2.0.0-win-gs-x64.exe /quiet

ARG files=.\\bin\\Release\\netcoreapp2.0\\publish
COPY $files .\\appcode

ARG NewRelic=.\\newrelic
COPY $NewRelic .\\newrelic

ENV ASPNETCORE_URLS http://+:80
EXPOSE 80

ENTRYPOINT ["dotnet", ".\\YOUR_APP_NAME.dll"]
3. Finish installation for Windows Docker containers

Build and run the Docker container.

Install for Linux Docker containers

The .NET Core 2.0 agent supports running within a Linux Docker container, including the Linux Docker images preinstalled by Microsoft with .NET Core 2.0.

1. Prepare your application directory
  1. Install Docker.

  2. Create your web application and publish it locally, making sure to publish using the appropriate Linux runtime identifier (RID) for the Linux version you plan to use in your container. For more information, see Microsoft's dotnet-publish documentation.

  3. Download the appropriate New Relic .Net Core 2.0 agent package from New Relic's download site into a newrelic folder in the application root.

2. Create a Dockerfile

Instructions for writing a Dockerfile or docker-compose.yml file that creates a working container vary depending on your Linux version. The following example uses the Microsoft-published Docker image that contains the .NET Core 2.0 SDK on Debian 9.

  1. Create the Dockerfile in your application root.

  2. Edit your Dockerfile:

    • Reference the microsoft/dotnet:2.0.0-sdk-2.0.2-stretch Docker image.

    • Define your entry point.

    • Set your working directory.

    • Set the New Relic environment variables.

      ENV CORECLR_ENABLE_PROFILING=1 \
      CORECLR_PROFILER={36032161-FFC0-4B61-B559-F6C5D41BAE5A} \
      CORECLR_NEWRELIC_HOME=/path/to/newrelic-netcore20-agent \
      CORECLR_PROFILER_PATH=/path/to/newrelic-netcore20-agent/libNewRelicProfiler.so \
      NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
      NEW_RELIC_APP_NAME=YOUR_APP_NAME
  3. Copy your published application files to the image.

  4. Copy the newrelic directory to the image.

  5. Install the newrelic-netcore20-agent-linux_VERSION_amd64.deb package.

  6. Set the ASPNETCORE_URLS environment variable to the correct port.

  7. Expose the port referenced by ASPNETCORE_URLS.

Linux Dockerfile
FROM microsoft/dotnet:2.0.0-sdk-2.0.2-stretch

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

ARG runtimeIdentifier=debian-x64
ARG files=./bin/Release/netcoreapp2.0/$runtimeIdentifier/publish
COPY $files ./appcode

ARG NewRelic=./newrelic
COPY $NewRelic ./newrelic

RUN dpkg -i ./newrelic/newrelic-netcore20-agent-linux*.deb

ENV ASPNETCORE_URLS http://+:80
EXPOSE 80

WORKDIR /app/appcode
ENTRYPOINT ["dotnet", "./YOUR_APP_NAME.dll"]
3. Finish installation for Linux Docker containers

Build and run the Docker container.

Build the Docker container

The steps to build your Docker container are similar for Windows and Linux.

Be sure to set the port forwarding to point to the port from the ASPNETCORE_URLS setting in your Dockerfile.

Use the following command to build the image. Replace tagName with your tag name.

docker build . -t tagName

Run the Docker container

To start a container, use the appropriate command for your operating system. Replace imageTagName with your image tag name.

Windows host running Windows images

Access your application using the Docker container's IP address rather than the address of the Docker host.

  1. Find the IP address of your container:

    From your container instance

    From your container instance, run this PowerShell command:

    docker exec -it containerName powershell

    Then run ipconfig in the shell.

    On the Docker host

    On the Docker host, run:

    docker network inspect networkName

    Then find the IP information for your container.

  2. Run the image:

    docker run -it -p 80:80 imageTagName
Linux images
docker run -it -p 80:80 imageTagName

As long as your app is receiving traffic, data should appear within a few minutes. If not, see No data appears.

For more help

Recommendations for learning more: