How do I keep a Docker log tail following a container that restarts under Docker Compose?
Tares keeps a docker_logs tail following a Compose container across restarts when you set container to the Compose service name and add compose_file. Use this when the service has no fixed container_name. The compose_file value is an absolute path, or a path relative to where the daemon runs. The console form has the same compose_file field.
How it works
The Docker logs connector tails a running container’s logs and creates one event per line. It keeps all lines by default, and you can narrow them with optional match and drop regex filters.
When a container runs under Compose and has no fixed container_name, a container name is not a stable handle. Set these two fields instead:
container: the Compose service name, for example the name of the service as it appears in your Compose file.compose_file: the path to yourdocker-compose.yml. It can be an absolute path, or relative to where the daemon runs.
With compose_file set, the tail follows restarts of the container. Without it, the source tails the container you named and does not follow restarts.
The source needs access to the Docker daemon. Run taresd on the host, or mount the Docker socket and include the Docker CLI in the image. If you run Tares in the container image, the socket mount and the CLI are what give it that access.
This fits the log-watching side of AI SRE: once the lines arrive as events, you can filter, label and act on them like any other source.
Set it up
- Confirm that
taresdcan reach the Docker daemon. On the host that is the default. In a container, mount the Docker socket and include the Docker CLI in the image. - Find the Compose service name. You can ask a connected agent: “Use tares to find my running containers and ingest the api-server’s logs.” The agent calls
discover_docker, which scans running containers and proposes one source per candidate. It then runstest_sourceas a dry run that tails a few lines, andcreate_sourceto save it. - Or use the console. Open Sources → Add source → docker_logs, set
containerto the service name, and click Discover to list the running containers to pick from. Because the container runs under Compose, also fill incompose_file, then save. - Or declare the source as YAML. Set
containerto the service name and addcompose_file:
- name: logs
connector: docker_logs
poll: 5s
config:
container: api-server
compose_file: /absolute/path/to/docker-compose.yml
labels:
- { name: service, const: api-server, primary: true }- If you prefer the API, send the same object with
POST /api/sources. - Verify. Open the source in the console. Recent events shows lines on the next poll. If nothing arrives, check that
taresdcan rundocker logsfor that container, since that is the same access the source needs.
Optional fields you can add under config:
| field | use |
|---|---|
match | keep only lines matching a regex, for example ERROR|WARN |
drop | skip lines matching a regex, for example HTTP/1.1" to drop access logs |
label_pattern | a regex with named groups that turns parts of each line into label context |
What you get
- A log tail tied to the Compose service, so it follows the container when it restarts.
- One Tares event per log line, searchable and usable by your agents and triggers.
- The same setup from the console form, the YAML object, a connected agent or
POST /api/sources. - Optional noise control with
matchanddrop, and per-line labels withlabel_pattern.
When something else fits
- If the container has a fixed container_name and does not run under Compose, set
containerto that name (as shown bydocker ps) and leavecompose_fileout. - If you need to find which containers exist before choosing one, use Discover in the console or the
discover_dockertool first, then come back to setcompose_file.
Related
Still stuck? Get help