Exercise: build a log-collection stack with Compose

  1. Step 1 — Set up the project directory structure
  2. Step 2 — Write vector.yaml with three log sources
  3. Step 3 — The most important point of this exercise: the sink points at the service name
  4. Step 4 — Write compose.yaml for the two services
  5. Step 5 — Validate in two layers before creating containers
  6. Step 6 — Start up and check each port
  7. Step 7 — Source 1 — push logs over HTTP and verify
  8. Step 8 — Source 2 — collect the logs of every container
  9. Step 9 — Source 3 — prepare the client machine: timezone and NTP FIRST
  10. Step 10 — Configure rsyslog on the client machine to forward to Vector
  11. Step 11 — Verify the protocol trap
  12. Step 12 — Query with LogsQL
  13. Step 13 — Verify persistence
  14. Illustration 1 — Project directory structure
  15. Illustration 2 — vector validate
  16. Illustration 3 — docker compose ps
  17. Illustration 4 — Port check
  18. Illustration 5 — Mounts of the vector service
  19. Illustration 6 — LogsQL query after pushing HTTP logs
  20. Illustration 7 — Built-in Docker labels
  21. Illustration 8 — timedatectl
  22. Illustration 9 — The protocol trap
  23. Illustration 10 — Persistence across down/up
  24. References
  25. Related articles

Estimated time: 60 minutes.

In the VictoriaLogs article, the log-collection system was built with docker run for VictoriaLogs and systemd for Vector — two ways of managing a single system.

This exercise rewrites the whole stack as one compose.yaml file and extends Vector to three log sources: HTTP JSON, syslog from another server, and the logs of every container on the host.

You need two machines: one running Docker (the stack host) and one client that only needs rsyslog.

Acceptance: (1) both docker compose config and vector validate are clean before up; (2) the three ports 9428 / 8686 / 9000 are listening, curl :8686/health responds, and vmui opens;

(3) logs pushed over HTTP can be queried back with _msg: and {host="..."}; (4) newly created containers are collected automatically,

and you can facet by container_name and image without changing the configuration; (5) logs from the client machine arrive on port 9514 once timezone/NTP are synchronized;

(6) after down and up -d, old logs can still be queried.

Step 1 — Set up the project directory structure

The project has three parts in one directory: compose.yaml, vector.yaml and a data directory. Every ./... path in the compose file is resolved relative to the location of that file.

mkdir -p ~/docker-practice/observability-lab/victoria-logs-data
cd ~/docker-practice/observability-lab
ls -la
id -u; id -g

Note: The victoria-logs-data directory must exist and be writable before startup, otherwise the VictoriaLogs container restarts continuously (Docker: bind mounts).

Step 2 — Write vector.yaml with three log sources

The configuration has three sources: http_server on 9000 receives application JSON, syslog on 9514 receives logs from other servers, and docker_logs collects the logs of every container.

The remap transform applies only to the HTTP source; the other two sources go into the sink as they are.

cat > vector.yaml <<'EOF'
api:
  enabled: true
  address: 0.0.0.0:8686

sources:
  http_input:
    type: http_server
    address: 0.0.0.0:9000
    decoding:
      codec: json

  source_syslogudp:
    type: syslog
    address: 0.0.0.0:9514
    mode: udp

  source_docker:
    type: docker_logs

transforms:
  normalize:
    type: remap
    inputs:
      - http_input
    source: |
      .timestamp = now()
      .host = "docker-lab"
      .source = "vector-http"
      if !exists(.message) {
        .message = encode_json(.)
      }

sinks:
  victorialogs:
    type: http
    inputs:
      - normalize
      - source_syslogudp
      - source_docker
    uri: http://victorialogs:9428/insert/jsonline?_stream_fields=host,source&_msg_field=message&_time_field=timestamp
    compression: gzip
    encoding:
      codec: json
    framing:
      method: newline_delimited
    healthcheck:
      enabled: false
EOF

cat vector.yaml

Note: Three parameters on the uri: _msg_field=message selects the message field, _time_field=timestamp selects the time field,

and _stream_fields=host,source selects the pair of fields that identify the log stream (VictoriaLogs:Vector setup).

The old encoding key of http_server has been replaced by decoding.codec — copying from old documentation will keep Vector from starting (Vector: http_server).

Step 3 — The most important point of this exercise: the sink points at the service name

The sink must point at http://victorialogs:9428/..., not an IP and not 127.0.0.1. Inside the Vector container, loopback is Vector itself.

In the earlier build, Vector ran under systemd on the host, so 127.0.0.1:9428 was correct; in the container version it is wrong.

grep -n "uri:" vector.yaml

Note: The symptom when it points to the wrong place: Vector runs normally, there is no obvious connection-error log, yet VictoriaLogs is empty — the hardest kind of failure to track down.

Services on the same project network resolve each other by name (Compose: networking).

Step 4 — Write compose.yaml for the two services

In the compose file, VictoriaLogs takes its parameters through command and mounts the data directory from the host; Vector depends on VictoriaLogs via depends_on,

publishes three ports and mounts three things: the configuration file, the Docker socket, and Docker's log directory.

cat > compose.yaml <<'EOF'
services:
  victorialogs:
    image: docker.io/victoriametrics/victoria-logs:v1.52.0
    container_name: victorialogs-lab
    restart: unless-stopped
    command:
      - -storageDataPath=/victoria-logs-data
      - -retentionPeriod=7d
    ports:
      - "9428:9428"
    volumes:
      - ./victoria-logs-data:/victoria-logs-data
    networks:
      - observability-net

  vector:
    image: timberio/vector:0.57.0-debian
    container_name: vector-lab
    restart: unless-stopped
    depends_on:
      - victorialogs
    ports:
      - "8686:8686"
      - "9000:9000"
      - "9514:9514/udp"
    volumes:
      - ./vector.yaml:/etc/vector/vector.yaml:ro
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
      - type: bind
        source: /var/lib/docker
        target: /var/lib/docker
    networks:
      - observability-net

networks:
  observability-net:
    driver: bridge
EOF

cat compose.yaml

Note: Mounting /var/run/docker.sock is equivalent to granting that container control over Docker on the whole host — do it only for a trusted agent.

The image tags are pinned so the lab is reproducible (Compose file reference, Vector: install on Docker).

Step 5 — Validate in two layers before creating containers

Validate in two layers: the first checks the compose syntax, the second runs vector validate in a throwaway container against the exact configuration file that will be used.

Do not move on until the configuration is clean.

docker compose config

docker run --rm \
  -v "$PWD/vector.yaml:/etc/vector/vector.yaml:ro" \
  timberio/vector:0.57.0-debian \
  validate /etc/vector/vector.yaml

Note: If you skip the second layer, Vector configuration errors only surface once the stack is half-running,

and the error message is buried in the combined log of the whole project (docker compose config).

If validate reports source not found, check that vector.yaml is a real file and not a symbolic link.

Step 6 — Start up and check each port

Check the ports with ss before curl, to tell "the service is not listening" apart from "the service is listening but returns an error". Note that 9514 is UDP, so you must use ss -lnup.

docker compose up -d
docker compose ps
ss -lntp | grep -E ":(9428|8686|9000) "
ss -lnup | grep -E ":9514 "
curl -s http://127.0.0.1:9428/ | head -5
curl -s http://127.0.0.1:8686/health

Note: The query UI is available at http://<IP_DOCKER_HOST>:9428/select/vmui — it is built into VictoriaLogs, with nothing extra to install (VictoriaLogs quickstart).

The Vector API on 8686 has no authentication — publish it only inside the lab network.

Step 7 — Source 1 — push logs over HTTP and verify

This is the simplest path, used to confirm that the Vector-to-VictoriaLogs link works before trying the other two sources.

curl --fail --show-error \
  -X POST -H 'Content-Type: application/json' \
  -d '{"message":"hello from docker vector lab","level":"info","app":"demo-web"}' \
  http://127.0.0.1:9000/

for i in 1 2 3 4 5; do
  curl --silent --show-error \
    -X POST -H 'Content-Type: application/json' \
    -d "{\"message\":\"docker lab event $i\",\"level\":\"info\",\"app\":\"demo-web\"}" \
    http://127.0.0.1:9000/
done

docker compose logs --tail 50 vector

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_msg:"docker lab"' \
  --data-urlencode 'limit=20'

Note: The nested double quotes inside the loop must be escaped as \" because the $i variable has to be expanded — outer single quotes would not expand it.

Vector's log must not contain any ERROR line related to the sink.

Step 8 — Source 2 — collect the logs of every container

Check the mounts first, then run a NEW container to prove the agent automatically picks up containers created afterwards without any configuration change.

docker inspect vector-lab --format '{{json .Mounts}}'

docker run --rm hello-world

docker compose logs --tail 30 vector

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=container_name:*' \
  --data-urlencode 'limit=20'

Note: If the HTTP source arrives but no container logs do, the Mounts list is missing /var/run/docker.sock. Add it to the service and run docker compose up -d --force-recreate vector.

The container_name and image labels are attached automatically by the docker_logs source (Vector: docker_logs).

Step 9 — Source 3 — prepare the client machine: timezone and NTP FIRST

This is the quietest trap in the exercise: with a clock mismatch the logs still arrive, but they fall outside the time window you are looking at, so it looks as if they never arrived.

Do this step before configuring rsyslog.

timedatectl
timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl set-ntp true
hostnamectl set-hostname client-01
timedatectl
hostnamectl

Note: Run it on both machines and compare: same timezone, NTP synchronized is yes, and the clock offset is no more than a few seconds (timedatectl).

The hostname is the label you will filter logs by later, so set it first, not afterwards.

Step 10 — Configure rsyslog on the client machine to forward to Vector

The client machine does not need Docker. A single @ means UDP, a double @@ means TCP. Replace <IP_DOCKER_HOST> with the real IP of the machine running the stack.

cat >> /etc/rsyslog.conf <<'EOF'
*.* @<IP_DOCKER_HOST>:9514
EOF

systemctl restart rsyslog
systemctl status rsyslog --no-pager

logger "test message from client-01"

Note: The protocol must match in three places: rsyslog (@ or @@), mode in vector.yaml,

and the protocol when publishing the port in compose (rsyslog:actions,

Vector:syslog).

Step 11 — Verify the protocol trap

Try telnet to port 9514. With the UDP configuration, failing to connect is correct. To use TCP, change all three places and then recreate the vector service.

command -v telnet || apt-get install -y telnet
telnet <IP_DOCKER_HOST> 9514

nc -zv <IP_DOCKER_HOST> 9514
printf "test udp syslog\n" | nc -u -w 2 <IP_DOCKER_HOST> 9514

grep -n "9514" /etc/rsyslog.conf
grep -n -A 2 "source_syslogudp" vector.yaml
grep -n "9514" compose.yaml

Note: This is a common mistake: the port is published as TCP by default while vector.yaml declares mode: udp, so telnet cannot connect — that is not an incident.

Minimal Ubuntu 24.04 does not ship telnet; if it reports command not found, install it, or use nc -zv for TCP and nc -u for UDP.

After editing vector.yaml you must run docker compose up -d --force-recreate vector, because Vector reads its configuration at startup.

Step 12 — Query with LogsQL

Start with a broad query to confirm logs exist, then narrow it down. In vmui, widen the time range and raise the number of displayed rows before concluding the logs have not arrived.

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=*' \
  --data-urlencode 'limit=20'

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query={host="docker-lab"}' \
  --data-urlencode 'limit=20'

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_msg:"client-01"' \
  --data-urlencode 'limit=20'

Note: In the UI, the overview tab shows the distribution by image and container_name — a quick way to narrow things down when the host has dozens of containers (LogsQL).

Step 13 — Verify persistence

Send an identifiable message, run down and then up -d, then query that same message again. This step proves the data lives outside the container lifecycle.

curl --fail --show-error \
  -X POST -H 'Content-Type: application/json' \
  -d '{"message":"persistent-log-before-recreate","level":"info"}' \
  http://127.0.0.1:9000/

du -sh ./victoria-logs-data

docker compose down
docker compose up -d

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_msg:"persistent-log-before-recreate"' \
  --data-urlencode 'limit=20'

docker stats --no-stream victorialogs-lab vector-lab

Note: Old logs can still be queried because -storageDataPath points at the mount point, and the real directory is ./victoria-logs-data on the host. down does not delete that directory —

to wipe the lab data you must rm it manually, and that action is irreversible (Docker:bind mounts).

Illustration 1 — Project directory structure

The project directory has all three required parts.

ls -la

Result:

total 20
drwxr-xr-x 3 root root 4096 Aug  8 09:12 .
-rw-r--r-- 1 root root  912 Aug  8 09:11 compose.yaml
-rw-r--r-- 1 root root  742 Aug  8 09:10 vector.yaml
drwxr-xr-x 4 root root 4096 Aug  8 09:14 victoria-logs-data

Note: If the victoria-logs-data directory is missing or not writable, the VictoriaLogs container restarts continuously.

Illustration 2 — vector validate

The Vector configuration must validate cleanly before up.

docker run --rm \
  -v "$PWD/vector.yaml:/etc/vector/vector.yaml:ro" \
  timberio/vector:0.57.0-debian \
  validate /etc/vector/vector.yaml

Result:

√ Loaded ["/etc/vector/vector.yaml"]
√ Component configuration
-------------------------------------
                Validated

Note: If this step reports an error, Vector prints the exact component name and the offending configuration line — fix it until it is clean before running up.

Illustration 3 — docker compose ps

Both services are Up, and Vector started after VictoriaLogs.

docker compose up -d
docker compose ps

Result:

NAME                IMAGE                                              SERVICE        STATUS         PORTS
victorialogs-lab    victoriametrics/victoria-logs:v1.52.0              victorialogs   Up 18 seconds  0.0.0.0:9428->9428/tcp
vector-lab          timberio/vector:0.57.0-debian                      vector         Up 16 seconds  0.0.0.0:8686->8686/tcp, 0.0.0.0:9000->9000/tcp, 0.0.0.0:9514->9514/udp

Note: depends_on only guarantees start order, not that VictoriaLogs is ready to accept connections — Vector retries on its own, which is enough for this exercise.

Illustration 4 — Port check

The port check covers three TCP ports and one UDP port.

ss -lntp | grep -E ":(9428|8686|9000) "
ss -lnup | grep -E ":9514 "

Result:

LISTEN 0  4096  0.0.0.0:9428  0.0.0.0:*  users:(("docker-proxy",pid=4412,fd=7))
LISTEN 0  4096  0.0.0.0:8686  0.0.0.0:*  users:(("docker-proxy",pid=4519,fd=7))
LISTEN 0  4096  0.0.0.0:9000  0.0.0.0:*  users:(("docker-proxy",pid=4531,fd=7))
UNCONN 0  0     0.0.0.0:9514  0.0.0.0:*  users:(("docker-proxy",pid=4544,fd=7))

Note: The syslog port shows up as UNCONN because it is UDP — you only see it with ss -lnup; ss -lntp will not list it.

Illustration 5 — Mounts of the vector service

The vector service must have all three mounts.

docker inspect vector-lab --format '{{json .Mounts}}'

Result:

[
  {"Type":"bind","Source":"/root/docker-practice/observability-lab/vector.yaml",
   "Destination":"/etc/vector/vector.yaml","Mode":"ro","RW":false},
  {"Type":"bind","Source":"/var/run/docker.sock",
   "Destination":"/var/run/docker.sock","RW":true},
  {"Type":"bind","Source":"/var/lib/docker",
   "Destination":"/var/lib/docker","RW":true}
]

Note: Without /var/run/docker.sock, the docker_logs source is completely silent: the service is up, the configuration is valid, and no container logs arrive.

Illustration 6 — LogsQL query after pushing HTTP logs

The query returns the HTTP logs, proving the Vector-to-VictoriaLogs link works.

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_msg:"docker lab"' \
  --data-urlencode 'limit=5'

Result:

{"_time":"2026-08-08T02:41:07.512Z","_stream":"{host=\"docker-lab\",source=\"vector-http\"}","_msg":"docker lab event 1","app":"demo-web","level":"info"}
{"_time":"2026-08-08T02:41:07.688Z","_stream":"{host=\"docker-lab\",source=\"vector-http\"}","_msg":"docker lab event 2","app":"demo-web","level":"info"}
{"_time":"2026-08-08T02:41:07.845Z","_stream":"{host=\"docker-lab\",source=\"vector-http\"}","_msg":"docker lab event 3","app":"demo-web","level":"info"}

Note: The _msg and _time fields match the _msg_field and _time_field declared on the uri; _stream is built from the _stream_fields=host,source pair.

Illustration 7 — Built-in Docker labels

Logs collected through docker_logs come with Docker labels already attached, so no extra configuration is needed.

docker run --rm hello-world

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=container_name:*' \
  --data-urlencode 'limit=3'

Result:

{"_time":"2026-08-08T02:44:19.204Z","_msg":"Hello from Docker!","container_name":"quirky_hopper","container_id":"9f21ab4c7e0d","image":"hello-world","stream":"stdout"}
{"_time":"2026-08-08T02:44:19.204Z","_msg":"This message shows that your installation appears to be working correctly.","container_name":"quirky_hopper","image":"hello-world","stream":"stdout"}

Note: This container was created after the agent was already running — the fact that its logs still arrive is evidence that the docker_logs source picks up new containers automatically.

Illustration 8 — timedatectl

Time synchronization is a prerequisite for logs from the client machine.

timedatectl

Result:

               Local time: Sat 2026-08-08 09:52:31 +07
           Universal time: Sat 2026-08-08 02:52:31 UTC
                Time zone: Asia/Ho_Chi_Minh (+07, +0700)
System clock synchronized: yes
              NTP service: active

Note: Run it on both machines and compare. System clock synchronized: no or differing timezones is the quietest cause of logs "not arriving".

Illustration 9 — The protocol trap

Telnet to a UDP port cannot connect, and that is the correct result.

telnet 192.0.2.10 9514

Result:

Trying 192.0.2.10...
telnet: Unable to connect to remote host: Connection refused

Note: vector.yaml declares mode: udp, so nothing is listening for TCP on that port.

Check UDP with nc -u, or switch to TCP in all three places: @@ in rsyslog, mode: tcp in vector, and the protocol when publishing the port.

Illustration 10 — Persistence across down/up

After down and then up -d, old logs can still be queried.

docker compose down
docker compose up -d

curl --get --fail --show-error \
  http://127.0.0.1:9428/select/logsql/query \
  --data-urlencode 'query=_msg:"persistent-log-before-recreate"' \
  --data-urlencode 'limit=5'

Result:

[+] Running 3/3
 ✔ Container vector-lab        Removed
 ✔ Container victorialogs-lab  Removed
 ✔ Network observability-lab_observability-net  Removed
{"_time":"2026-08-08T02:58:02.117Z","_stream":"{host=\"docker-lab\",source=\"vector-http\"}","_msg":"persistent-log-before-recreate","level":"info"}

Note: The containers and network were removed but the data is still there: it lives in ./victoria-logs-data on the host, outside the container lifecycle.

References

Related articles

Exercise: build a log-collection stack with Compose