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.
| Specification | What it passes to the Agent | If removed |
|---|---|---|
-v /var/run/docker.sock:…:ro | Connection to the Docker daemon. Used to discover containers and fetch stdout / stderr | Other containers cannot be found, and the live container view does not appear |
-v /proc/:/host/proc/:ro | Host-side process information | Monitoring as a host does not hold together |
-v /sys/fs/cgroup/:…:ro | Host-side cgroup information (resource usage per container) | Per-container CPU / memory cannot be obtained |
--cgroupns host / --pid host | The host's cgroup namespace and PID namespace | Even with the two mounts above exposed, the contents cannot be traced correctly |
-e DD_API_KEY / -e DD_SITE | The key for sending and the destination | Nothing can be sent without the key. With no site specified, data goes to datadoghq.com |
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).
| Variable | Role | If you run without deciding it |
|---|---|---|
DD_API_KEY | API key (required) | Starts but cannot send anything |
DD_SITE | Destination for metrics / traces / logs. Default is datadoghq.com | Organizations on AP1 or EU see nothing on their own screens |
DD_HOSTNAME | Hostname used when automatic detection fails | If hostname detection fails, it stops right after starting |
DD_TAGS | Space-separated host tags (key1:value1 key2:value2) | Cannot filter by host |
DD_ENV | The env tag attached to all emitted data | Production and staging data get mixed |
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:roThe 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
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).
| Symptom | Cause | Fix |
|---|---|---|
| The container stops right after starting | Automatic hostname detection failed | Specify explicitly with DD_HOSTNAME or DD_HOSTNAME_FILE |
| After switching to file collection, logs from old containers do not arrive | After migration, only new containers are read from files | Make all containers read from files with DD_LOGS_CONFIG_DOCKER_CONTAINER_FORCE_USE_FILE |
| Logs are duplicated after switching back to socket collection | Existing containers are read through both routes | The official docs state the duplication explicitly. Be aware of it before switching back |
| Large volumes of the Agent's own logs arrive | No exclusion specified | Add DD_CONTAINER_EXCLUDE. In Compose, do not wrap the value in quotation marks |
| Does not work as documented on containerd / Podman | The CLI differs. Log collection support is limited | Substitute nerdctl / podman for docker. containerd has namespace exclusion variables |
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.
| Feature | Default | Variable to change it |
|---|---|---|
| Trace reception (APM) | Enabled | DD_APM_ENABLED |
| Live container view | Enabled (when the socket is visible) | - |
| Log collection | Disabled | DD_LOGS_ENABLED |
| Live process collection | Disabled | DD_PROCESS_CONFIG_PROCESS_COLLECTION_ENABLED |
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 statusWhere 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.
dockeris listed without warnings under Running Checks indocker 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
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.