Skip to Content
Tares

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 your docker-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

  1. Confirm that taresd can 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.
  2. 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 runs test_source as a dry run that tails a few lines, and create_source to save it.
  3. Or use the console. Open Sources → Add source → docker_logs, set container to the service name, and click Discover to list the running containers to pick from. Because the container runs under Compose, also fill in compose_file, then save.
  4. Or declare the source as YAML. Set container to the service name and add compose_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 }
  1. If you prefer the API, send the same object with POST /api/sources.
  2. Verify. Open the source in the console. Recent events shows lines on the next poll. If nothing arrives, check that taresd can run docker logs for that container, since that is the same access the source needs.

Optional fields you can add under config:

fielduse
matchkeep only lines matching a regex, for example ERROR|WARN
dropskip lines matching a regex, for example HTTP/1.1" to drop access logs
label_patterna 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 match and drop, and per-line labels with label_pattern.

When something else fits

  • If the container has a fixed container_name and does not run under Compose, set container to that name (as shown by docker ps) and leave compose_file out.
  • If you need to find which containers exist before choosing one, use Discover in the console or the discover_docker tool first, then come back to set compose_file.

Still stuck? Get help

Last updated on