---
title: Install and configure OpenTelemetry Collector Contrib to monitor Docker
source: https://docs.newrelic.com/docs/opentelemetry/integrations/docker/install-otelcol-contrib
---

This page installs OpenTelemetry Collector Contrib on a Linux host, configures it to collect Docker container metrics, and verifies data reaches New Relic.

## Compatibility and requirements [#requirements]

### Supported

-   Docker Engine API version 1.25 or later

### You need

-   A valid New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key)
-   Access to the Docker socket (typically `/var/run/docker.sock`)
-   Network access from the host to the Docker Engine socket and to a [New Relic OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp/#configure-endpoint-port-protocol)
-   Read permissions on `/var/lib/docker/containers/` for log collection (typically root or docker group membership)

## Install OpenTelemetry Collector Contrib [#install]

> #### 💡 TIP
>
> If you already have OpenTelemetry Collector Contrib installed, skip this step and continue to [Set up Docker socket permissions](#permissions).

Download and install the OpenTelemetry Collector Contrib following the [official installation guide](https://github.com/open-telemetry/opentelemetry-collector-contrib/releases/latest).

## Set up Docker socket permissions [#permissions]

The collector needs access to the Docker socket to collect container metrics. Grant the collector user access to the Docker group.

```bash
# Add otelcol-contrib user to docker group
sudo usermod -aG docker otelcol-contrib

# Verify the user was added
groups otelcol-contrib

# Restart Docker to apply group changes
sudo systemctl restart docker

# Test Docker socket access
sudo -u otelcol-contrib docker ps
```

If the test command succeeds and shows your containers, you've configured permissions correctly.

If this reports `permission denied` instead of listing containers, see [Permission denied errors](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/troubleshooting#permission-errors).

## Configure the collector [#configure]

For OpenTelemetry Collector Contrib, merge the receivers, processors, exporters, and service pipelines into your configuration file (typically `/etc/otelcol-contrib/config.yaml`).

```yaml
receivers:
  # Docker Stats Receiver - collects container metrics
  docker_stats:
    endpoint: unix:///var/run/docker.sock
    collection_interval: 15s
    timeout: 5s
    api_version: "1.25"
    # Most metrics required for New Relic UI are enabled by default:
    # CPU: container.cpu.usage.total, container.cpu.utilization
    # Memory: container.memory.usage.total, container.memory.percent
    # Network: container.network.io.usage.tx_bytes, container.network.io.usage.rx_bytes
    #          container.network.io.usage.tx_dropped, container.network.io.usage.rx_dropped
    # Storage: container.blockio.io_service_bytes_recursive
    #
    # The following metrics need to be explicitly enabled:
    metrics:
      # Required for New Relic UI
      container.pids.count:
        enabled: true
      # Additional network error metrics
      container.network.io.usage.tx_errors:
        enabled: true
      container.network.io.usage.rx_errors:
        enabled: true

processors:
  # Resource detection - adds host metadata
  resourcedetection:
    detectors: [system, docker]
    system:
      resource_attributes:
        host.name:
          enabled: true
        host.id:
          enabled: true
  # Batch processor - optimizes data transmission
  batch:
    timeout: 30s
    send_batch_size: 512
  # Transform processor - removes descriptions and units
  transform:
    metric_statements:
      - context: metric
        statements:
          - set(description, "")
          - set(unit, "")

exporters:
  # New Relic OTLP Exporter
  otlp_http/newrelic:
    endpoint: ${env:NEWRELIC_OTLP_ENDPOINT}
    headers:
      api-key: ${env:NEWRELIC_LICENSE_KEY}
    compression: gzip
    timeout: 30s
    retry_on_failure:
      enabled: true
      initial_interval: 5s
      max_interval: 30s
      max_elapsed_time: 300s

service:
  pipelines:
    metrics:
      receivers: [docker_stats]
      processors: [resourcedetection, transform, batch]
      exporters: [otlp_http/newrelic]
```

### Configuration parameters [#configuration-parameters]

The following table describes the key configuration parameters for the `docker_stats` receiver and exporter:

| Parameter                   | Description                                                                                                                                                         |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `endpoint` (`docker_stats`) | Enter the path to the Docker socket the collector connects to. Default: `unix:///var/run/docker.sock`                                                               |
| `collection_interval`       | Set how often the collector scrapes container stats. Default: `15s`                                                                                                 |
| `timeout`                   | Set how long the collector waits for the Docker Engine API to respond before giving up. Default: `5s`                                                               |
| `api_version`               | Enter the Docker Engine API version your host supports. Default: `1.25`                                                                                             |
| `NEWRELIC_LICENSE_KEY`      | Enter your New Relic license key.                                                                                                                                   |
| `NEWRELIC_OTLP_ENDPOINT`    | Enter the New Relic OTLP endpoint for your region. See [New Relic OTLP endpoints](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp/). |

Save the file and ensure the `otelcol-contrib` system user can read it.

> #### 💡 TIP
>
> Optionally, you can also collect logs from your containers. For configuration steps, see [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/advanced-configuration#logs).

**Configure the systemd service:**

Now you'll configure the OpenTelemetry Collector Contrib service with your authentication credentials. This involves setting environment variables for your New Relic license key and OTLP endpoint.

1.  Create a systemd override directory:
    ```bash
    sudo mkdir -p /etc/systemd/system/otelcol-contrib.service.d
    ```

2.  Create `environment.conf` with your configuration. Replace `YOUR_LICENSE_KEY` with your New Relic license key and `YOUR_OTLP_ENDPOINT` with the appropriate endpoint for your region:
    ```bash
    cat <<EOF | sudo tee /etc/systemd/system/otelcol-contrib.service.d/environment.conf
    [Service]
    Environment="NEWRELIC_LICENSE_KEY=YOUR_LICENSE_KEY"
    Environment="NEWRELIC_OTLP_ENDPOINT=YOUR_OTLP_ENDPOINT"
    EOF
    ```

## Restart the collector [#start]

Reload systemd and restart the collector:

```bash
sudo systemctl daemon-reload
sudo systemctl restart otelcol-contrib

# Verify the collector is running
sudo systemctl status otelcol-contrib
```

## Verify your install [#verify]

Within 5 minutes of completing the install, confirm data reaches New Relic.

-   Go to **[one.newrelic.com](https://one.newrelic.com) > All Entities** and search by hostname or container name. Your Docker containers should appear as entities.
-   Run this NRQL query and confirm it returns at least 1 row:
    ```sql
    FROM Metric SELECT count(*) WHERE container.runtime = 'docker' SINCE 10 minutes ago
    ```

If you don't see data within 5 minutes, see [Docker monitoring troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/troubleshooting).

Your Docker containers are reporting data. Want to collect logs too? [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/advanced-configuration) covers log collection setup.

## Related articles [#related-articles]

-   [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/advanced-configuration): Optional configuration beyond the minimum setup, including log collection
-   [Docker metrics reference](https://docs.newrelic.com/docs/opentelemetry/integrations/docker/metrics-reference): Complete metric and attribute reference, with alerting recommendations
-   [NRQL alert conditions](https://docs.newrelic.com/docs/alerts/create-alert/create-alert-condition/create-nrql-alert-conditions/): Set up proactive alerting on container metrics
