Home > Software > How to Deploy OpenTelemetry Collector with Docker Compose: A Step-by-Step Guide

How to Deploy OpenTelemetry Collector with Docker Compose: A Step-by-Step Guide

Anastasios Antoniadis

Learn how to deploy the OpenTelemetry Collector using Docker Compose with our step-by-step guide. Discover how to create a Docker Compose file, configure the OTel Collector, and start enhancing your observability infrastructure efficiently.

Docker (1)

The OpenTelemetry Collector offers a unified way to receive, process, and export telemetry data (metrics, logs, and traces), making it an invaluable tool for observability. Deploying the OpenTelemetry (OTel) Collector using Docker Compose simplifies the setup process, enabling you to configure and scale your observability infrastructure efficiently. This article will guide you through creating a Docker Compose file for deploying an OTel Collector and a basic configuration to get you started.

Prerequisites

Before proceeding, ensure you have the following:

  • Docker: Installed and running on your machine.
  • Docker Compose: Installed on your machine. Docker Compose is included with Docker Desktop for Windows and Mac, but may require a separate installation on Linux.
  • Familiarity with OpenTelemetry: Basic understanding of OpenTelemetry concepts and components.

Step 1: Create a Docker Compose File

Begin by creating a docker-compose.yml file in your desired directory. This YAML file will define the OpenTelemetry Collector service and any other services you wish to include in your observability stack.

Step 2: Define the OpenTelemetry Collector Service

Open the docker-compose.yml file in a text editor and add the following service definition for the OTel Collector:

version: '3'
services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    container_name: otel-collector
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
    ports:
      - "4317:4317" # gRPC
      - "4318:4318" # HTTP
      - "8888:8888" # Prometheus metrics exposed by the collector
    restart: unless-stopped

Here’s what each key in the service definition means:

  • image: Specifies the Docker image to use for the OTel Collector. This example uses the latest tag of the otel/opentelemetry-collector-contrib image, which includes a variety of processors and exporters.
  • container_name: Sets a custom name for easier reference.
  • command: Provides the command to run inside the container. Here, it specifies the path to the collector’s configuration file.
  • volumes: Maps a configuration file from your host to the container. You will create this file in the next step.
  • ports: Exposes ports for receiving telemetry data. The example above exposes the default gRPC and HTTP ports for receiving telemetry data, and a port for Prometheus metrics exposed by the collector.
  • restart: Ensures the container restarts automatically unless stopped manually.

Step 3: Create the OTel Collector Configuration File

Next, create an otel-collector-config.yaml file in the same directory as your docker-compose.yml. This file will contain the configuration for the OTel Collector. Below is a simple example configuration:

receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  logging:
    loglevel: debug

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [logging]
    metrics:
      receivers: [otlp]
      exporters: [logging]

This configuration sets up the OTel Collector to receive telemetry data over OTLP (OpenTelemetry Protocol) via both gRPC and HTTP. It then exports the received data to the console (stdout) with a debug log level.

Step 4: Start the OpenTelemetry Collector

With your docker-compose.yml and configuration file ready, start the OTel Collector by running the following command in the directory containing your Docker Compose file:

docker compose up -d

This command will pull the OTel Collector image (if not already pulled), create a container as defined in your Docker Compose file, and start the container in detached mode.

Step 5: Verify the Deployment

Verify that the OTel Collector is running and properly configured by checking the container’s logs:

docker logs otel-collector

If your system is already sending data to the collector, you should see an output indicating that the collector has started, along with any telemetry data being logged to the console.

Conclusion

Deploying the OpenTelemetry Collector with Docker Compose allows you to streamline the setup of your observability infrastructure. Following the steps outlined in this guide, you can configure the OTel Collector to receive, process, and export telemetry data according to your needs. The flexibility of Docker Compose means you can easily scale your deployment or integrate additional services into your observability stack as your requirements evolve.

Anastasios Antoniadis
Follow me
Latest posts by Anastasios Antoniadis (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x