Install the New Relic Node.js agent in a Docker container by adding it to your package.json and loading it at startup.
Prerequisites
Requirement | Details |
|---|---|
New Relic account | You need a New Relic account and your . |
Node.js version | See Node.js agent compatibility and requirements for supported versions. |
Docker | Docker installed and a Dockerized Node.js application. |
Advertencia
Do not include your license key in your Dockerfile or Docker image. Pass it as an environment variable at runtime instead.
Add the agent to your application
Add newrelic to your package.json:
"newrelic": "latest"Then update your Dockerfile or startup command to load the agent. How you do this depends on whether your app uses CommonJS or ESM:
Importante
If you cannot use the -r flag, add require('newrelic') as the first line of your app's main module. Do not use this approach with Babel or other transpilers — it will cause instrumentation issues.
Configure the agent
Pass your app name and license key as environment variables when running the container. These are the only required settings:
$docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \> -e NEW_RELIC_APP_NAME="Your Application Name" \> YOUR_IMAGE_NAME:latestYou can also set configuration via ENV directives in your Dockerfile:
ENV NEW_RELIC_APP_NAME="Your Application Name"For all other configuration options, see Node.js agent configuration.
Verify data is flowing
Build and run your container, then send at least two requests to your application. Wait 2–3 minutes and open one.newrelic.com > APM to look for your app by name.
Sugerencia
App not appearing? See Troubleshooting your Node.js installation.
Related articles
- Node.js agent compatibility and requirements — Supported Node.js versions.
- Node.js agent configuration — All available configuration settings.
- Install the Node.js agent — Standard npm install method.