You can use the APM Node.js agent to instrument Node.js applications deployed in Docker containers. This document will show you how to build, configure, and deploy a New Relic-instrumented version of your Dockerized Node.js application.
Instrument your container
With just a few additions your existing Dockerfile can be used with the New Relic Node.js agent. You'll configure the agent by running your new Docker image with environment variables set.
"newrelic": "latest",You can also install a specific version or use any of the other options provided by the
package.jsonformat. Check the Node.js agent release notes for information about past agent versions.
- Add this line to your Dockerfile so the agent can run without a configuration file:
- Build your Docker image the way you normally do.
- To run your Docker app with the agent enabled, add your license key and app name to your
docker runcommand as environment variables:
docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \ -e NEW_RELIC_APP_NAME="Your Application Name" \ your_image_name:latest
Other configuration options
$ docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \ -e NEW_RELIC_APP_NAME="Your Application Name" \ -e NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true \ your_image_name:latest
You can also set configuration options in your Dockerfile using
ENV NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true \ NEW_RELIC_LOG=stdout # etc.
We strongly recommend not including your license key in your Dockerfile or Docker image. See our documentation on license security for more information.