> For the complete documentation index, see [llms.txt](https://docs.controltheory.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/docker.md).

# Docker

Collect container logs, and forward OpenTelemetry metrics and traces, from a Docker host.

Collect container logs from a Docker host with the ControlTheory agent, which runs as a single container on the host and forwards data to Dstl8. Applications on the host can also send the agent their own logs, metrics and traces over OpenTelemetry (OTLP), and the agent forwards those too.

### How it works

The **ControlTheory agent** runs as one container (named `aigent`) on each Docker host. It reads the logs of the other containers on that host and forwards them to Dstl8. It also listens on the host for OpenTelemetry (OTLP) logs, metrics and traces, so applications on the same host can send their own telemetry to it:

| Host port | Protocol  |
| --------- | --------- |
| `4317`    | OTLP/gRPC |
| `4318`    | OTLP/HTTP |

Add one Docker source per host, or per group of hosts you want to treat as one environment. Each source gets its own admission token.

### Before you start

* A Linux host with Docker installed, and a user that can run `docker` commands (run the install command as that user, or with `sudo`).
* `curl` on the host, and outbound HTTPS access from the host to Dstl8.
* To read other containers' logs, the agent container runs privileged and mounts the Docker socket, the Docker container log directory (read-only), and `/var/log`. If your security policy doesn't allow that on a host, don't install the agent there.
* Host ports `4317` and `4318` must be free. The agent always publishes its OTLP listeners on these two ports, so a host that already runs an OpenTelemetry collector on them can't run the agent until that collector moves to other ports.
* The command creates a `./data` directory in the folder you run it from, which the agent uses for its own state. Run it from a folder that will stay in place. If you run the command with `sudo`, the folder is owned by root, so removing it later also needs `sudo`.

### Add a Docker source

#### 1. Create the source in Dstl8

From **Sources**, click **Add Source** and select **Docker**. On the **Configure Docker Source** step, fill in:

| Field                   | Notes                                                                                  |
| ----------------------- | -------------------------------------------------------------------------------------- |
| Name                    | Required. A unique name to identify this source.                                       |
| Cluster Name (optional) | Name used to attribute telemetry to this host or group of hosts. Defaults to `docker`. |
| Deployment Environment  | Required. Environment name for filtering and grouping, e.g. `prod`, `staging`, `dev`.  |

Click **Create**.

#### 2. Install the agent

The **Install the Collector** step shows a ready-to-run command with your organization, token and source values already filled in. Click **Copy** and run it on your Docker host. It has this shape:

```bash
curl -fsSL https://install.controltheory.com/scripts/install.sh -o install.sh && chmod +x ./install.sh && ./install.sh \
  -i <org-id> \
  -p docker \
  --docker-token <YOUR_DOCKER_TOKEN> \
  --org-api-endpoint <org-api-url> \
  --cluster-name <cluster-name> \
  -e <environment> \
  --source-id <source-id>
```

Always copy the command from Dstl8 rather than typing it, so the token and IDs are correct. Treat the token like a password. Don't paste it into tickets or commit it to source control.

When the script finishes it prints `ControlTheory Agent install done`. Click **Done** in Dstl8.

To see the command again later, open **Sources**, open the Docker source's actions menu (gear icon) and select **Install Script**.

#### 3. Verify

On the host, confirm the container is running:

```bash
docker ps | grep aigent
docker logs aigent
```

In Dstl8, the source shows **Listening for telemetry** and turns **Healthy** once the agent connects, usually within a couple of minutes. Streams appear on the **Sources** page as your containers write logs. Then [assign the streams to a workspace](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources.md#assigning-streams-to-workspaces) so they're accessible there.

### Send your own telemetry to the agent

Applications on the host can export OTLP logs, metrics and traces to the agent, instead of (or as well as) writing logs to stdout. Metrics show up under **Explore → Metrics** and traces under **Explore → Traces**, organized by service; see [Metrics](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/metrics.md) and [Traces](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/traces.md). Use an address that reaches the host from where the application runs:

* An application running directly on the host: `localhost`.
* An application in a container: not `localhost`, which is the container itself. Use the host's IP address, the Docker bridge gateway (usually `172.17.0.1`), or `host.docker.internal` (on Linux, start the container with `--add-host=host.docker.internal:host-gateway`).

For an application using an OpenTelemetry SDK, set the standard environment variable:

```bash
# OTLP/HTTP
OTEL_EXPORTER_OTLP_ENDPOINT=http://<host-address>:4318
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

# or OTLP/gRPC
OTEL_EXPORTER_OTLP_ENDPOINT=http://<host-address>:4317
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
```

Set the protocol along with the endpoint: SDKs differ in their default, and one sending HTTP to the gRPC port (or the other way round) fails to export.

For an OpenTelemetry Collector, point its exporter at the agent and add it to each pipeline you want in Dstl8:

```yaml
exporters:
  otlp/dstl8:
    endpoint: <host-address>:4317
    tls:
      insecure: true

service:
  pipelines:
    logs:
      exporters: [otlp/dstl8]
    metrics:
      exporters: [otlp/dstl8]
    traces:
      exporters: [otlp/dstl8]
```

Set `service.name` on everything you send (or `OTEL_SERVICE_NAME` in an SDK). It names the service your metrics and traces are filed under, and ties them to the service's logs.

The OTLP listeners are plain (unencrypted) and unauthenticated, so only expose these ports to networks you trust, and use your firewall or security group to keep them off the public internet.

### Update the agent

Uninstall the running agent with the **Uninstall Script** (see [Uninstall](#uninstall)), then run the install command from **Install Script** again. The install command always creates a container named `aigent`, so the old one must be removed first. Updating also brings the agent version that forwards metrics and traces, if yours predates them (see [Agent versions](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/metrics/collecting.md#agent-versions)).

### Uninstall

Open **Sources**, open the Docker source's actions menu (gear icon) and select **Uninstall Script**. Copy the command and run it on the Docker host. It has this shape:

```bash
curl -fsSL https://install.controltheory.com/scripts/install.sh -o install.sh && bash install.sh \
  -o uninstall \
  -p docker
```

Deleting a Docker source shows the same uninstall command first, with **Continue to Delete**. Uninstalling stops collection; the source stays in Dstl8 until you delete it. The `./data` folder the install created can be deleted once the agent is gone.

If you can't run the script, removing the container by hand also stops the agent:

```bash
docker stop aigent && docker rm aigent
```

### Troubleshooting

| Symptom                                                        | What to check                                                                                                                                                                                                                                                      |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Source stays **Listening for telemetry**                       | Run `docker logs aigent`. Confirm the host can reach Dstl8 over HTTPS (proxies and egress firewalls are the usual cause), and that the command was copied in full with the correct token.                                                                          |
| `the agent container 'aigent' is already running on this host` | An agent is already installed on this host. Uninstall it first, then rerun.                                                                                                                                                                                        |
| `permission denied` from Docker                                | Run the command as a user that can access the Docker socket, or with `sudo`.                                                                                                                                                                                       |
| Ports `4317` or `4318` already in use                          | Another service on the host (often an OpenTelemetry collector) is using them. Stop it or move it to other ports, then run the install command again.                                                                                                               |
| Metrics or traces don't arrive                                 | Check the application exports to port `4318` with `http/protobuf`, or to `4317` with `grpc`, and that the exporter is on its `metrics` and `traces` pipelines. An agent installed before metrics and traces were supported forwards logs only: update it as above. |
| Source is **Healthy** but a container's logs are missing       | Make sure the container writes to stdout/stderr with Docker's default `json-file` logging driver, and that you've assigned the stream to a workspace.                                                                                                              |

### Tips

* Install a separate Docker source per environment so streams don't collide, and set **Deployment Environment** accordingly.
* Running containers on Amazon ECS or Kubernetes instead? See [Amazon ECS](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/amazon-ecs.md) and [Kubernetes](https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/kubernetes.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.controltheory.com/controltheory-documentation/dstl8-docs/sources/docker.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
