Running the Datadog Agent in Docker - Where You Get Stuck and How to Decide

This article reads the docker run arguments for running the Datadog Agent as a container on a Docker host through the lens of "what stops being visible if you remove it." It organizes how to write it in Compose, the environment variables and mounts to add for log collection, how to translate it for containerd / Podman, and verification with docker exec.

Why the docker run Arguments Are So Long

When you put the Datadog Agent on a Docker host, you run the Agent itself as a container rather than installing a package on the host. The official minimal command consists of two namespace specifications (--cgroupns host / --pid host), three read-only mounts, two environment variables, and the image registry.datadoghq.com/agent:7 (as of September 2026; source: Docker Agent for Docker, containerd, and Podman). It looks long because it lines up the specifications that let the isolated Agent see information about the host and the other containers.

The specifications in the official minimal docker run and what each passes to the Agent
SpecificationWhat it passes to the AgentIf removed
-v /var/run/docker.sock:…:roConnection to the Docker daemon. Used to discover containers and fetch stdout / stderrOther containers cannot be found, and the live container view does not appear
-v /proc/:/host/proc/:roHost-side process informationMonitoring as a host does not hold together
-v /sys/fs/cgroup/:…:roHost-side cgroup information (resource usage per container)Per-container CPU / memory cannot be obtained
--cgroupns host / --pid hostThe host's cgroup namespace and PID namespaceEven with the two mounts above exposed, the contents cannot be traced correctly
-e DD_API_KEY / -e DD_SITEThe key for sending and the destinationNothing can be sent without the key. With no site specified, data goes to datadoghq.com
Source: Docker Agent for Docker, containerd, and Podman (Manually run the Datadog Docker Agent / Global options) and Docker Log collection (description of each -v)

As for the procedure itself, the in-app installation screen generates the docker run command for you, so we leave that to it. The purpose of this article is to let you understand each generated line, transcribe it into Compose, add logs, and fix the places where you get stuck.

Five Environment Variables to Decide for the Container Version

The items the host version writes in datadog.yaml, the container version receives as environment variables. How to decide the key and site is the same as in the previous day's Linux installation article, so we do not repeat it. What the container version additionally requires you to decide is how to pass the hostname and tags (as of September 2026; source: Docker Agent for Docker, containerd, and Podman).

The first five environment variables to decide (within the scope of Global options)
VariableRoleIf you run without deciding it
DD_API_KEYAPI key (required)Starts but cannot send anything
DD_SITEDestination for metrics / traces / logs. Default is datadoghq.comOrganizations on AP1 or EU see nothing on their own screens
DD_HOSTNAMEHostname used when automatic detection failsIf hostname detection fails, it stops right after starting
DD_TAGSSpace-separated host tags (key1:value1 key2:value2)Cannot filter by host
DD_ENVThe env tag attached to all emitted dataProduction and staging data get mixed
Source: Docker Agent for Docker, containerd, and Podman (Environment variables / Global options)

For environments where it cannot be passed as an environment variable, DD_HOSTNAME_FILE, which reads the hostname from a file on the host, is also provided. The reason to decide DD_ENV from the start is that, among tags, the env tag is the filtering axis that cuts across all products; if you add it later, only the data from before it was added falls out of the filter.

How to Write It in Compose

The official Compose guide transcribes each docker run argument into the environment and volumes of the datadog service (as of September 2026; source: Compose and the Datadog Agent).

services:
  datadog:
    pid: host
    environment:
      - DD_API_KEY=${DD_API_KEY}
      - DD_SITE=<DD_SITE>
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /proc/:/host/proc/:ro
      - /sys/fs/cgroup:/host/sys/fs/cgroup:ro

The fork here is whether to bake integration configuration into the image or pass it via labels on the target containers (Autodiscovery).

What to Add to Pick Up Container Logs

With the minimal command as is, logs are not collected. The official log collection page shows a form with two environment variables, two mounts, and one exclusion added (as of September 2026; source: Docker Log collection).

  • 1. DD_LOGS_ENABLED=true - Wakes up the Logs Agent and makes it read the log instructions in the configuration files
  • 2. DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true - Adds a log configuration that targets all containers
  • 3. -v /var/lib/docker/containers:…:ro - Reads container logs from files (possible from 7.27.0 / default from 7.33.0)
  • 4. -v /opt/datadog-agent/run:…:rw - Keeps the last line read for each container on the host so logs are not lost on restarts or connection interruptions
  • 5. DD_CONTAINER_EXCLUDE="name:datadog-agent" - Does not collect the Agent's own logs and metrics
Source: Docker Log collection (The commands related to log collection). 1 and 2 are the "collect" specifications, 3 and 4 are "do not lose," and 5 is "do not collect extra"

These five divide into three kinds of roles. Without 1 and 2 nothing is collected; without 3 and 4 collection goes through the socket and misses data on restarts; without 5 even the Agent's own logs count toward ingestion volume. Having targeted all containers, attaching source and service to logs is the job of the com.datadoghq.ad.logs label on the monitored container side (source: Compose and the Datadog Agent). What happens after the source arrives is left to the Log Pipeline glossary page, and how to write the label is left to the Autodiscovery glossary page. For designing the volume you send, read the Log Management explanation first.

Five Places to Get Stuck, Each Answered on an Official Page

The stuck points raised within the official documentation for the Docker version can be organized into five (as of September 2026; source: Docker Log collection / Docker Agent for Docker, containerd, and Podman).

Five places where the Docker version of the Agent gets stuck
SymptomCauseFix
The container stops right after startingAutomatic hostname detection failedSpecify explicitly with DD_HOSTNAME or DD_HOSTNAME_FILE
After switching to file collection, logs from old containers do not arriveAfter migration, only new containers are read from filesMake all containers read from files with DD_LOGS_CONFIG_DOCKER_CONTAINER_FORCE_USE_FILE
Logs are duplicated after switching back to socket collectionExisting containers are read through both routesThe official docs state the duplication explicitly. Be aware of it before switching back
Large volumes of the Agent's own logs arriveNo exclusion specifiedAdd DD_CONTAINER_EXCLUDE. In Compose, do not wrap the value in quotation marks
Does not work as documented on containerd / PodmanThe CLI differs. Log collection support is limitedSubstitute nerdctl / podman for docker. containerd has namespace exclusion variables
Source: Docker Log collection (Docker container log collection from a file / Overview) and Docker Agent for Docker, containerd, and Podman (Global options / Ignore containers)

The first one, the hostname, is also the first item raised in the official troubleshooting: "if the container stops right after starting, suspect hostname detection" (source: Agent Troubleshooting). For the fifth one, containerd, you can narrow the targets per namespace with DD_CONTAINERD_NAMESPACES and DD_CONTAINERD_EXCLUDE_NAMESPACES.

What Is Enabled by Default, and What Is Not

There are features that run even though they are not written in docker run, and features that do not run unless written (as of September 2026; source: Docker Agent for Docker, containerd, and Podman). DD_APM_ENABLED for trace collection defaults to true, and the container version of the Agent has its trace receiving port open from the start. The live container view is enabled by default as long as the Docker socket is visible. On the other hand, DD_PROCESS_CONFIG_PROCESS_COLLECTION_ENABLED for process collection and DD_LOGS_ENABLED for log collection belong to the optional collection Agents that the official docs describe as "disabled by default for security or performance reasons," and they do not run unless specified explicitly.

Default enabled / disabled (Docker version of the Agent)
FeatureDefaultVariable to change it
Trace reception (APM)EnabledDD_APM_ENABLED
Live container viewEnabled (when the socket is visible)-
Log collectionDisabledDD_LOGS_ENABLED
Live process collectionDisabledDD_PROCESS_CONFIG_PROCESS_COLLECTION_ENABLED
Source: Docker Agent for Docker, containerd, and Podman (Global options / Optional collection Agents)

The "enabled by default" side affects billing. For hosts that do not use APM, make the decision to flip DD_APM_ENABLED to false in advance.

Verify That It Is Running with docker exec

The verification command is the same agent status as the host version, but you run it inside the container (source: Agent Commands).

docker exec -it <CONTAINER_NAME> agent status

Where to look is the same Running Checks section as the host version, and for the Docker version the first gate is whether the docker check is listed without warnings. On the Datadog side, since the Docker version of the Agent is designed to send an event every time it starts / restarts (source: Docker Agent for Docker, containerd, and Podman), if the Agent's startup event appears in the Events Explorer, the path through to sending is working.

  • 1. The Agent container is Up in docker ps
  • 2. docker is listed without warnings under Running Checks in docker exec … agent status
  • 3. The Agent's startup event arrives in the Events Explorer
  • 4. If you added logs, containers are listed in the Logs Agent section of status
Source: Agent Commands (Agent information) and Docker Agent for Docker, containerd, and Podman (Events)

The next fork beyond this is Kubernetes, and the deployment patterns and the items to decide before adoption are summarized in the Container Monitoring explanation.

References

Share