Skip to content

Docker Containers

Benjamin Fernandes edited this page Jun 16, 2014 · 13 revisions

Introduction

If you are using Docker on one of your hosts, you will be interested in the Docker Integration. But you may also want to install the Agent or DogStatsD inside a Docker Container. This page will explain you how to do it.

To make your Agent run on a container, you will need to create a Docker image containing the Agent and your configuration. We already provide a base image containing the Agent and its dependencies so that you just have to add a layer with your configuration.

WARNING: Even with the --privileged flag, some system metrics will be incorrect or missing. Metrics such as CPU, network or process memory usage will be restricted to the container. But load, memory, disk usage and latency will reflect the state of the host. Some integrations may be broken too.

If you want to get all system metrics from your Docker host, you will need to install the Agent outside of Docker.

See also:

Quick Start

The default image is ready-to-go, you just need to set your hostname and API_KEY in the environment. Don't forget to set the --privileged flag to get host metrics.

docker run -d --privileged --name dd-agent -h `hostname` -e API_KEY=apikey_3 datadog/docker-dd-agent

Configuration

To configure the Agent, you will need to build a Docker image on top of our image.

Create a Dockerfile to set your specific configuration or to install dependencies.

FROM datadog/docker-dd-agent

# Example: MySQL
RUN apt-get install python-mysqldb -qq --no-install-recommends
ADD mysql.yaml /etc/dd-agent/conf.d/mysql.yaml

Build it.

docker build -t dd-agent-image .

Then run it like the datadog/docker-dd-agent image.

docker run -d --privileged --name dd-agent -hhostname-e API_KEY=apikey_3 dd-agent-image

DogStatsD

If you want to run DogStatsD alone, give a look at docker-dogstatsd.

This container also runs DogStatsD, so the documentation from docker-dogstatsd also apply to it.

Logs

Supervisor logs

Basic information about the Agent execution are available through the logs command.

docker logs dd-agent

If you want to get access to the real Agent logs, you will need to use volumes. A full documentation of volumes is available on Docker documentation. Here are two examples.

Container volume

Create a volumes for the log directory when running the image by adding -v /var/log/datadog to the run command.

Logs are now stored in a volume that you can access from other containers with the --volumes-from parameter. For examples, if you want to look into it:

docker run --volumes-from dd-agent -name dd-agent-log-reader ubuntu /bin/bash

It will open a shell, then go to /var/log/datadog to see Agent logs.

Host directory as a volume

You can also use a host directory, let's say /var/docker-volumes/dd-agent/log, as a log directory. For that, add the option -v /var/docker-volumes/dd-agent/log:/var/log/datadog

Now you should see Agent logs into /var/docker-volumes/dd-agent/log on your host.

Logging verbosity

You can set logging to DEBUG verbosity by adding to your Dockerfile:

RUN sed -i -e"s/^.*log_level:.*$/log_level: DEBUG/" /etc/dd-agent/datadog.conf
Clone this wiki locally