---
title: Install the Node.js agent in Docker
source: https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent-docker
---

Install the New Relic Node.js agent in a Docker container by adding it to your `package.json` and loading it at startup.

## Prerequisites [#prerequisites]

| Requirement           | Details                                                                                                                                                                                    |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **New Relic account** | You need a [New Relic account](https://newrelic.com/signup) and your license key.                                                                                                          |
| **Node.js version**   | See [Node.js agent compatibility and requirements](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent) for supported versions. |
| **Docker**            | Docker installed and a Dockerized Node.js application.                                                                                                                                     |

> #### ⚠️ CAUTION
>
> 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 [#install]

Add `newrelic` to your `package.json`:

````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:

<CollapserGroup>
  <Collapser
    id="docker-cjs"
    title="App using CommonJS"
  >
    * `ENTRYPOINT`

      ```bash
      ENTRYPOINT ["node", "-r", "newrelic", "YOUR_PROGRAM.js"]
      ```

    * `CMD`

      ```bash
      CMD ["node", "-r", "newrelic", "YOUR_PROGRAM.js"]
      ```

    * npm script such as `npm start`

      ```bash
      npm pkg set scripts.start="node -r newrelic your-program.js"
      ```
  </Collapser>
  <Collapser
    id="docker-esm"
    title="App using ESM"
  >
    * `ENTRYPOINT`

      ```bash
      ENTRYPOINT ["node", "--import", "newrelic/esm-loader.mjs", "-r", "newrelic", "YOUR_PROGRAM.js"]
      ```

    * `CMD`

      ```bash
      CMD ["node", "--import", "newrelic/esm-loader.mjs", "-r", "newrelic", "YOUR_PROGRAM.js"]
      ```

    * npm script such as `npm start`

      ```bash
      npm pkg set scripts.start="node --import newrelic/esm-loader.mjs -r newrelic your-program.js"
      ```
  </Collapser>
</CollapserGroup>

<Callout variant="important">
  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.
</Callout>

````

## Configure the agent [#configure]

Pass your app name and license key as environment variables when running the container. These are the only required settings:

````bash
docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \
           -e NEW_RELIC_APP_NAME="Your Application Name" \
           YOUR_IMAGE_NAME:latest
```

You can also set configuration via `ENV` directives in your Dockerfile:

```dockerfile
ENV NEW_RELIC_APP_NAME="Your Application Name"
```

For all other configuration options, see [Node.js agent configuration](/docs/apm/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration).

````

## Verify data is flowing [#verify]

Build and run your container, then send at least two requests to your application. Wait 2–3 minutes and open [one.newrelic.com > APM](https://one.newrelic.com/apm) to look for your app by name.

> #### 💡 TIP
>
> App not appearing? See [Troubleshooting your Node.js installation](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/troubleshooting/troubleshooting-your-nodejs-installation).

## Related articles [#related-docs]

-   [Node.js agent compatibility and requirements](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent) — Supported Node.js versions.
-   [Node.js agent configuration](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration) — All available configuration settings.
-   [Install the Node.js agent](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent) — Standard npm install method.
