Knowledge
A log-collection Compose stack: VictoriaLogs, Vector and rsyslog
Estimated time: 50 minutes.
Quick summary
-
Composing an entire infrastructure stack
- Why: The same log-collection system built in the VictoriaLogs lesson, but written as a single compose file: VictoriaLogs and Vector are two services on one network, declared in configuration instead of through two different installation procedures (Compose file reference). The earlier version ran VictoriaLogs with docker run and installed Vector with systemd — two ways of managing one system.
- When it breaks: When half the system is managed with docker run and the other half with systemd, nobody can rebuild it exactly as it was, and every change has to be remembered in two places.
- In real deployments: One stack, one compose file, one project directory in Git — even for internal infrastructure, not just applications.
-
Services call each other by service name, not by IP
- Why: Vector's sink points to http://victorialogs:9428/insert/jsonline?... — victorialogs is a service name, resolved through the project network's internal DNS (Compose: networking).
- When it breaks: Putting 127.0.0.1 points at the Vector container itself: the service runs normally, with no obvious error, yet VictoriaLogs stays empty.
- In real deployments: Write every internal address in container configuration using the service name; container IPs change every time a container is recreated, so they are not a reliable anchor.
-
Three log sources in one Vector
- Why: http_server on 9000 receives JSON from applications; syslog on 9514/udp receives logs from other servers; docker_logs collects the logs of every container on the host (http_server, syslog, docker_logs). A single sink merges all three paths into VictoriaLogs.
- When it breaks: Concluding "logs are not arriving" for the whole stack when in fact only one source is broken — each source fails in its own way and must be accepted separately.
- In real deployments: Verify each source with its own test-injection command, and record that command in the operations documentation to reuse during incidents.
-
The mounts the docker_logs source needs
- Why: Vector inside a container needs /var/run/docker.sock to talk to Docker, and /var/lib/docker to read the container log files (Vector: install on Docker).
- When it breaks: Without the mounts, the docker_logs source is silent: the service is up, the configuration is valid, and no container logs arrive.
- In real deployments: Mounting docker.sock is equivalent to granting control of the host's Docker — only for trusted agents, and never expose the agent's management port.
-
Two layers of validation before up
- Why: docker compose config catches compose syntax errors (docker compose config); a temporary container running vector validate catches Vector configuration errors before any service has been created.
- When it breaks: With a bad Vector configuration the service does not start, and the error message is buried in the log of the whole project — far more time-consuming than checking beforehand.
- In real deployments: Put both validate commands into the CI checks: a configuration that is not clean never reaches the server.
-
Logs survive down/up thanks to a bind mount
- Why: The -storageDataPath parameter points at the mount point, and the real directory is ./victoria-logs-data on the host — outside the container lifecycle (VictoriaLogs quickstart).
- When it breaks: If you forget to mount the data directory from outside, every collected log disappears with the container the first time it is recreated.
- In real deployments: Set retention explicitly (-retentionPeriod), monitor the size of the data directory, and have a backup plan before increasing log volume.
-
Pushing syslog from machines without Docker
- Why: A client machine only needs one extra line in /etc/rsyslog.conf and a service restart: one @ sign means UDP, two @@ signs mean TCP (rsyslog: actions). Vector plays the role of the syslog receiver.
- When it breaks: If the protocol is declared inconsistently between rsyslog, vector.yaml and the way the port is published in compose, the connection fails with a very vague error message.
- In real deployments: Standardize on one protocol across the whole system and state it clearly in the documentation; UDP drops packets silently, TCP gives feedback but costs connections.
-
Timezone and NTP are prerequisites
- Why: Logs are tied to timestamps; a timezone mismatch or a missing NTP sync makes messages arrive but fall outside the time window being viewed (timedatectl).
- When it breaks: It looks like logs are not arriving, which leads to fixing the firewall and agent configuration even though the collection path was working all along.
- In real deployments: Set the timezone and enable NTP sync as soon as the machine is created, before installing any service — treat it as a step of the machine provisioning procedure.
-
LogsQL queries and the built-in Docker labels
- Why: The vmui interface is built into VictoriaLogs. Filter by content with _msg:, by log stream with {host="..."}, and by container_name or image using the labels the docker_logs source attaches automatically (LogsQL).
- When it breaks: An empty query caused by a time window that is too narrow is often misread as logs not having arrived — widen the window before concluding.
- In real deployments: Look at the distribution by image/container first to narrow the scope, then filter in detail — the way to search when a host has dozens of containers.
-
The ceiling of Compose and the path to Kubernetes
- Why: Compose orchestrates on a single host. A positioning scale: Docker is level 1, Compose level 3, Swarm level 4, Kubernetes level 9 (Kubernetes: components, Docker: Swarm mode). A commonly used pragmatic threshold: with fewer than 10 servers and an application that is not too large, Compose is enough.
- When it breaks: Moving to a cluster too early means taking on one more system to operate, when the original problem only needed good control of volumes and networks.
- In real deployments: When you genuinely must make the move: keep manifests in Git with CI/CD from day one, never hand-edit on the servers.
Step 1 — Build the directory structure for the stack
Three components in one project directory: compose.yaml, vector.yaml and the data directory. Every ./... path in a compose file is resolved relative to the location of that file itself (Compose file reference).
When it breaks: If files are scattered around, bind mounts point to the wrong place: Vector receives an empty configuration file, or VictoriaLogs writes data into an unintended directory.
mkdir -p ~/docker-practice/observability-lab/victoria-logs-data
cd ~/docker-practice/observability-lab
ls -la
Observe with:
pwd ; ls -la ; tree -L 2 (if available)
Notes: The victoria-logs-data directory must exist and be writable before startup, otherwise the VictoriaLogs container will restart continuously.
Step 2 — Write vector.yaml with three log sources
http_server receives JSON from applications, syslog receives logs from other servers, docker_logs collects the logs of every container on the host. The remap transform applies only to the HTTP source; the other two sources go into the sink as they are (http_server, syslog, docker_logs).
When it breaks: The old encoding key of http_server has been replaced by decoding.codec — copying old documentation makes Vector fail to start.
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
Observe with:
cat vector.yaml ; compare the input names in the sink with the declared source names
Notes: The three parameters on the uri tell VictoriaLogs which field is the content, which field is the time, and which pair of fields identifies the log stream. Note that .timestamp = now() overwrites the application's original timestamp — acceptable only in a lab.
Step 3 — Understand why the sink points to a service name, not an IP
Two services on the same observability-net network resolve each other through internal DNS by service name. Inside the Vector container, 127.0.0.1 is itself — not VictoriaLogs (VictoriaLogs: receiving logs from Vector).
When it breaks: Putting loopback here makes Vector run normally, with no obvious connection error, yet VictoriaLogs stays empty — the hardest kind of bug to find in this exercise.
grep -n "uri:" vector.yaml
docker compose exec vector getent hosts victorialogs
Observe with:
grep uri vector.yaml ; docker compose exec vector getent hosts victorialogs (after up)
Symptoms when it breaks:
- Vector runs with no errors, but querying VictoriaLogs returns nothing: the uri in vector.yaml points to http://127.0.0.1:9428 instead of http://victorialogs:9428
How to fix:
-
Change the uri to the service name, then recreate the vector service
sed -i "s#http://127.0.0.1:9428#http://victorialogs:9428#" vector.yaml && docker compose up -d
Notes: The VictoriaLogs container uses a distroless base image and therefore has no shell — an exec into it always fails. That is how the image is designed. The fact that Vector sends logs successfully is already proof that internal DNS works.
Step 4 — Write compose.yaml for the stack's two services
VictoriaLogs receives its parameters through command and mounts the data directory from the host; Vector depends on VictoriaLogs through depends_on, publishes three ports and mounts three things: the configuration file, the Docker socket and Docker's log directory (Compose file reference, Compose: depends_on).
When it breaks: Without the /var/run/docker.sock mount, the docker_logs source is silent; without the bind mount for the data directory, logs are lost the first time the container is recreated.
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
docker compose config
Observe with:
docker compose config ; docker inspect vector-lab --format "{{json .Mounts}}" (after up)
Notes: The image tags are pinned so the lab is reproducible. depends_on only guarantees the startup order, not that VictoriaLogs is ready to accept connections — Vector retries on its own, which is enough for this exercise.
Step 5 — Validate in two layers before creating any container
Layer one is docker compose config for compose syntax. Layer two is a temporary container running vector validate against the exact configuration file that will be used — catching errors before any service has been created (docker compose config).
When it breaks: If you skip layer two, Vector configuration errors only surface once the stack is half-running, and the error message is buried in the merged log of the whole project.
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
Observe with:
The output of compose config ; the Validated line at the end of the vector validate output
Symptoms when it breaks:
- vector validate reports an error at exactly the misconfigured block: Vector prints the component name and the error line, and the process exits with a non-zero code
- validate reports that it cannot find the configuration file: source not found — usually because vector.yaml is a symlink or the $PWD path is wrong
How to fix:
-
Check that the configuration file is a real file, not a symbolic link
ls -l vector.yaml ; readlink -f vector.yaml -
Fix the configuration until validate is clean before running up
docker run --rm -v "$PWD/vector.yaml:/etc/vector/vector.yaml:ro" timberio/vector:0.57.0-debian validate /etc/vector/vector.yaml
Step 6 — Start the stack and check each port
up -d pulls the images and then creates the two containers in the order given by depends_on. Check the ports with ss before curl to tell "the service is not listening" apart from "the service is listening but returns an error" (VictoriaLogs quickstart).
When it breaks: If you jump straight to the web interface without checking the ports, you cannot tell which layer the failure is in when the page does not open.
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
Observe with:
docker compose ps ; ss -lntp filtered for 9428/8686/9000 ; curl the health endpoint
Symptoms when it breaks:
- The victorialogs-lab container restarts continuously: docker compose logs victorialogs reports permission denied when writing to /victoria-logs-data
How to fix:
-
Grant write permission on the bind-mount directory on the host, then restart
sudo chown -R "$(id -u):$(id -g)" ./victoria-logs-data && chmod 755 ./victoria-logs-data && docker compose up -d
Notes: The query interface opens at http://<IP_DOCKER_HOST>:9428/select/vmui — it is built into VictoriaLogs, nothing extra to install.
Step 7 — Inject logs through the HTTP source and verify
The simplest source, used to confirm that the path from Vector to VictoriaLogs works before trying the other two sources (Vector: http_server).
When it breaks: If you try all three sources at once and see nothing, you cannot tell where it is stuck — accept them one at a time to narrow the scope.
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'
Observe with:
docker compose logs --tail 50 vector ; a LogsQL query on _msg
Notes: The nested double quotes in the loop must be escaped as " because the variable $i has to be expanded — outer single quotes would not expand it.
Step 8 — Collect the logs of every container through the docker_logs source
The docker_logs source receives logs directly through Docker and automatically attaches labels for container name, ID and image — so containers created later are still collected without changing the configuration (Vector: docker_logs).
When it breaks: Without the Docker socket mount, this source is completely silent: the service is up, the configuration is valid, and no container logs arrive.
docker inspect vector-lab --format '{{json .Mounts}}'
docker run --rm hello-world
curl -s http://127.0.0.1:8080/does-not-exist >/dev/null 2>&1 || true
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'
Observe with:
docker inspect vector-lab --format "{{json .Mounts}}" ; vmui filtered by container_name
Symptoms when it breaks:
- No container logs in VictoriaLogs even though the HTTP source still arrives: the Mounts list of vector-lab is missing /var/run/docker.sock
How to fix:
-
Add the Docker socket bind mount to the vector service, then recreate it
docker compose up -d --force-recreate vector
Notes: The container_name and image labels are already parsed by Vector in the Docker style, with no extra configuration — this is the advantage of collecting through Docker over reading log files.
Step 9 — Push syslog from a client machine to Vector
The client machine does not need Docker installed: add one line to /etc/rsyslog.conf pointing to port 9514 of the host running the stack. One @ sign means UDP, two @@ signs mean TCP (rsyslog: actions, Vector: syslog).
When it breaks: If the protocol is declared inconsistently in three places — rsyslog, the mode in vector.yaml, and the way the port is published in compose — the connection fails with a very vague error message.
timedatectl
timedatectl set-timezone Asia/Ho_Chi_Minh
timedatectl set-ntp true
timedatectl
hostnamectl set-hostname client-01
cat >> /etc/rsyslog.conf <<'EOF'
*.* @<IP_DOCKER_HOST>:9514
EOF
systemctl restart rsyslog
systemctl status rsyslog --no-pager
logger "test message from client-01"
Observe with:
timedatectl on both machines ; ss -lnup | grep 9514 on the host ; vmui filtered by the client's host
Symptoms when it breaks:
- The client's logs do not show up in the interface even though rsyslog runs normally: timedatectl differs in timezone between the two machines, or NTP synchronized reports no — the message arrives but falls outside the time window being viewed
- Trying telnet to port 9514 fails to connect: vector.yaml declares mode udp while telnet uses TCP — working as designed, not a fault. Note that Ubuntu 24.04 minimal does not ship telnet; use nc -zv for TCP and nc -u for UDP
How to fix:
-
Set the timezone and enable NTP sync on both machines, then try again
timedatectl set-timezone Asia/Ho_Chi_Minh && timedatectl set-ntp true && timedatectl -
Cross-check the protocol in three places: rsyslog (@ or @@), the mode in vector.yaml, and the protocol used when publishing the port
grep -n "9514" /etc/rsyslog.conf vector.yaml compose.yaml -
To use TCP, change all three places: @@ in rsyslog, mode tcp in vector, and publish the TCP port
docker compose up -d --force-recreate vector
Notes: Setting the hostname and timezone as soon as the machine is created is a step of the machine provisioning procedure, not something to fix later — the hostname is the label used to filter logs afterwards.
Step 10 — Query LogsQL in vmui
Start with a broad query to confirm there are logs, then narrow down: by content with _msg:, by log stream with {host="..."}, by container with container_name (LogsQL).
When it breaks: An empty query caused by a time window that is too narrow is often misread as logs not having arrived, leading to changes to a configuration that was correct.
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:"404"' \
--data-urlencode 'limit=20'
Observe with:
The vmui interface at :9428/select/vmui — the query tab and the overview tab to see the distribution
Notes: In the interface, increase the number of displayed rows and widen the time window from 5 minutes to 15 minutes before concluding there are no logs. The overview tab shows the distribution by image and container for quick scoping.
Step 11 — Verify persistence through down and then up
The data lives on the ./victoria-logs-data bind mount, so the container lifecycle does not affect it. The test: send an identifiable message, run down, up -d, then query for exactly that message again (Docker: bind mounts).
When it breaks: If you skip this check, a log-loss incident only surfaces when replacing containers in a real environment, exactly when you need the logs to investigate.
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 compose logs --tail 30
docker stats --no-stream victorialogs-lab vector-lab
Observe with:
du -sh ./victoria-logs-data before/after ; query again for the message that was sent
Notes: down does not delete the bind-mount directory. To delete the lab data you must rm that directory manually, and that action cannot be undone.
Step 12 — Position Compose on the scale spectrum and prepare the path to Kubernetes
Compose orchestrates on a single host: if the host dies, every service on that host dies, and there is no mechanism to move a service to another machine. The layer above is cluster orchestration with a separate control-plane and workers (Kubernetes: components, Docker: Swarm mode).
When it breaks: Moving to a cluster too early means taking on one more system to operate, when the original problem only needed good control of volumes and networks.
docker info --format "Server version: {{.ServerVersion}}"
docker compose ls
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
Observe with:
docker info to see the number of nodes ; compare the number of servers and services in the system you actually operate
Notes: A commonly used pragmatic threshold: with fewer than 10 servers and an application that is not too large, Docker with Compose is enough. When you genuinely must move to a cluster, the vocabulary changes — service becomes pod/deployment, volume becomes PersistentVolumeClaim, network becomes a CNI plugin you must choose yourself, with Ingress/Egress added — and manifests must live in Git with CI/CD from day one.
Common misconceptions
- Wrong: In the Vector container, pointing the sink at 127.0.0.1:9428 reaches VictoriaLogs because the two containers are on the same host. Right: Inside the Vector container, 127.0.0.1 is the Vector container itself. You must call VictoriaLogs by its service NAME: http://victorialogs:9428/...
Each container has its own network namespace, so its loopback does not lead to another container even on the same host. Services on the same network of a Compose project resolve each other through internal DNS by service name (Compose: networking, VictoriaLogs: receiving logs from Vector). This is the biggest difference when moving a stack from docker run to Compose: the earlier docker run version ran Vector under systemd on the host, so 127.0.0.1:9428 was correct; in the container version that address points back at itself. The characteristic symptom is that Vector runs normally, with no obvious connection-error logs, yet VictoriaLogs is empty. Consequence: every address in a container's configuration must be written with the service name, never an IP or loopback. In return, container IPs changing after each recreation has no effect at all.
- Wrong: Bind mounting the vector.yaml file into the container is enough for Vector to collect the logs of every container on the host. Right: The docker_logs source needs Vector to be able to talk to Docker: you must mount /var/run/docker.sock, and mount /var/lib/docker to read the log files. Without the mounts, that source is silent.
The docker_logs source connects to Docker to receive the log stream of running containers together with name/ID/image labels (Vector: docker_logs). When Vector runs in a container, the path to Docker is the host's socket — so the container version must mount it explicitly (Vector: install on Docker). Two ways of granting permission for the same purpose: the systemd installation only needs the user running Vector to be in the docker group; the container version needs the socket mounted. Both fail silently — the service is up, the configuration is valid, there are just no logs arriving. Security consequence: mounting /var/run/docker.sock is equivalent to granting that container control of the whole host's Docker. Only do it with a trusted agent, and do not expose the agent's management port to an untrusted network (Docker: bind mounts).
- Wrong: If logs do not arrive, the cause is a Vector fault or a firewall block. Right: The two most silent causes lie outside those two places: a timezone/NTP mismatch between the two machines, and a protocol declared inconsistently between compose, vector.yaml and rsyslog.
Logs are tied to timestamps; if the sending machine has a timezone mismatch or is not NTP-synchronized, the message still arrives but falls outside the time window being viewed in the interface, which looks like "no logs" (timedatectl). The second trap is the protocol: rsyslog uses one @ sign for UDP and two @@ signs for TCP (rsyslog: actions), while Vector's syslog source declares the mode explicitly (Vector: syslog) and compose publishes the port with its own protocol. These three places must agree. A common mistake: the port is published as TCP by default while vector.yaml declares mode udp, so telnet to that port fails to connect — which is exactly as it should be, not a fault. Consequence for the order of diagnosis: check timedatectl on both machines and cross-check the protocol in three places BEFORE opening the firewall or reading Vector's logs.
- Wrong: docker compose down loses every collected log, so you may only use stop. Right: VictoriaLogs data lives on the host's ./victoria-logs-data bind mount, so after down then up -d the old logs can still be queried.
By default a container writes into its own writable layer, which is lost with the container. But this stack mounts the data directory from outside via a bind mount and passes -storageDataPath pointing at exactly that mount point, so storage lives independently of the container lifecycle (Docker: bind mounts, VictoriaLogs quickstart). The acceptance test is: send a message with identifiable content, run down then up -d, and query for exactly that message again. If it is lost, the fault is in the mount or in the storageDataPath parameter, not in the down command. Consequence: down can be used freely to free ports and clean up containers. To delete the data for real you must delete the directory on the host manually — and that action cannot be undone.
- Wrong: Once you can use Compose, just scale out with Compose; you do not need Kubernetes. Right: Compose only orchestrates on ONE host: if the host dies, every service on that host dies, and Compose does not move services to another machine by itself. The pragmatic threshold is about 10 servers.
Compose is a single-host tool; for multiple hosts you must move up to cluster orchestration, which has a separate control-plane and workers along with a scheduler (Kubernetes: components). Docker Swarm used to be a middle path, but the ecosystem around it has been thinning out (Docker: Swarm mode). The pragmatic advice runs against the usual expectation: with fewer than 10 servers and an application that is not too large, Docker with Compose is enough — good control of volumes and networks already solves the problem, and it is much leaner and easier to maintain. Building a cluster just to run a log-collection system is operational cost that is not worth it. Consequence when you genuinely must move: both the vocabulary and the way of thinking change — service becomes pod/deployment, volume becomes PersistentVolumeClaim, network becomes a CNI plugin you must choose yourself, with Ingress/Egress added. And the prerequisite is that manifests live in Git with CI/CD from day one, never hand-edited on the servers.
Hands-on 1 — Build the log-collection stack with Compose
30 minutes
Rewrite the log-collection system built in the VictoriaLogs lesson as a single compose file, validate in two layers, then start it — acceptance through the HTTP source is the simplest path (VictoriaLogs quickstart).
docker compose config && docker compose up -d
Observe: docker compose ps ; ss filtered for 9428/8686/9000 ; curl Vector's /health ; vmui at :9428/select/vmui
1. Create ~/docker-practice/observability-lab/victoria-logs-data and then cd into the project directory.
The data directory exists and is writable.
2. Write vector.yaml with three sources (http_server :9000, syslog :9514 mode udp, docker_logs), a remap transform that applies only to the HTTP source, and a single sink merging all three that points to http://victorialogs:9428/insert/jsonline?....
The file reads back with the right content; the input names in the sink match the declared source names.
3. Write compose.yaml: the victorialogs service (command -storageDataPath and -retentionPeriod=7d, port 9428, bind mount ./victoria-logs-data) and the vector service (depends_on, ports 8686/9000/9514 udp, mounts vector.yaml:ro + /var/run/docker.sock + /var/lib/docker), network observability-net.
The file exists with the correct three-component structure in the project directory.
4. Validate layer one: docker compose config. Validate layer two: docker run --rm -v "$PWD/vector.yaml:/etc/vector/vector.yaml:ro" timberio/vector:0.57.0-debian validate /etc/vector/vector.yaml.
Both commands are clean. If there is an error, fix it until clean before moving to the next step.
5. docker compose up -d then docker compose ps, ss -lntp | grep -E ":(9428|8686|9000) " and curl -s http://127.0.0.1:8686/health.
Both services are Up; three TCP ports are listening; Vector's health endpoint responds.
6. Inject one JSON message into :9000, then the 5-message loop, then query _msg:"docker lab".
The query returns exactly the messages just sent; Vector's log has no ERROR lines related to the sink.
Analysis
Observation: The whole stack comes up with a single command, and the validate step catches errors before any container is created.
Mechanism: Compose creates the network and then the two containers in the order given by depends_on; Vector calls VictoriaLogs through internal DNS by service name.
Lesson: Internal infrastructure should also be described by configuration in Git, not by two different installation procedures.
Troubleshooting:
- The victorialogs-lab container restarts continuously: The ./victoria-logs-data directory lacks write permission. Run chown/chmod on the directory, then up -d again.
- Vector runs but the VictoriaLogs query is empty: Check that the uri in vector.yaml is http://victorialogs:9428, not 127.0.0.1.
- vector validate reports source not found: Check that vector.yaml is a real file, not a symbolic link, and that $PWD is the project directory.
Hands-on 2 — Collect every container's logs and search with LogsQL
25 minutes
Verify the docker_logs source: containers created AFTER the agent started are still collected, and the name/image labels are available for filtering with no extra configuration (Vector: docker_logs, LogsQL).
docker inspect vector-lab --format '{{json .Mounts}}'
Observe: The Mounts list of vector-lab ; the vmui query tab and overview tab
1. Check the mounts: docker inspect vector-lab --format '{{json .Mounts}}'.
All three mounts are present: vector.yaml, /var/run/docker.sock and /var/lib/docker.
2. Run a new container: docker run --rm hello-world.
That container's log appears in vmui — a container created after the agent is still collected.
3. Generate load against a running web container, including a non-existent path to produce a 404 status.
The web access log appears in the centralized log.
4. In vmui, query container_name:*, then open the overview tab, increase the number of displayed rows and widen the time window to 15 minutes.
You see the log distribution by container_name and image, already parsed in the Docker style.
5. Filter progressively: _msg:"404", then {host="docker-lab"}, then container_name:"<container-name>".
Each query narrows down to exactly the expected set of logs.
6. Send an identifiable message, run docker compose down then up -d, and then query for that same message again.
The old log can still be queried — proof that the data lives on the host's bind mount.
Analysis
Observation: Logs from new containers appear without changing the agent configuration; the name and image labels are available for filtering.
Mechanism: The docker_logs source receives the log stream directly through the Docker socket together with container metadata, so containers created later still fall within the collection scope.
Lesson: Collecting through Docker rather than reading log files is the right choice: the container ID changes every time it is recreated, while the labels are always there.
Troubleshooting:
- The HTTP source arrives but there are no container logs: The /var/run/docker.sock mount is missing. Add it to the vector service, then docker compose up -d --force-recreate vector.
- The query is empty even though logs were just generated: Widen the time window and increase the number of displayed rows before concluding. Also check docker compose logs --tail 50 vector.
Hands-on 3 — Push syslog from a client machine and handle two classic traps
30 minutes
A machine without Docker can also push logs: rsyslog points to Vector's syslog port. This exercise drills the two most silent traps — time mismatch and protocol mismatch (rsyslog: actions, timedatectl).
timedatectl && systemctl restart rsyslog
Observe: timedatectl on both machines ; ss -lnup | grep 9514 on the host ; vmui filtered by the client's hostname
1. On the client machine, set the hostname and timezone and enable NTP: hostnamectl set-hostname client-01, timedatectl set-timezone Asia/Ho_Chi_Minh, timedatectl set-ntp true.
timedatectl shows the correct timezone and NTP synchronized is yes.
2. Compare timedatectl on the machine running the stack with the client machine.
Both machines have the same timezone and the same time, off by no more than a few seconds.
3. Add the line *.* @<IP_DOCKER_HOST>:9514 to /etc/rsyslog.conf, then systemctl restart rsyslog and check systemctl status rsyslog.
The service is active (running), with no configuration errors.
4. Generate a message: logger "test message from client-01", then find it in vmui.
The message appears, and its timestamp matches the real time.
5. Try nc -zv <IP_DOCKER_HOST> 9514 (or telnet if it is installed — Ubuntu 24.04 minimal does not ship it).
The connection fails — as expected, because the configuration is UDP. This is the common protocol trap.
6. Switch to TCP in all three places: @@ in rsyslog, mode: tcp in vector.yaml, and publish the TCP port in compose. Run validate again, then up -d.
telnet connects and logs still arrive — proving the three places must match each other.
Analysis
Observation: Whether logs arrive depends on two conditions outside the agent configuration: correct time and a matching protocol.
Mechanism: Logs are tied to timestamps, so a time mismatch pushes messages outside the window being viewed; the protocol is declared in three places and the connection only succeeds when all three match.
Lesson: Order of diagnosis: check the time and protocol first, open the firewall afterwards. Setting the hostname and timezone as soon as the machine is created is a step of the machine provisioning procedure.
Troubleshooting:
- rsyslog runs normally but logs do not appear: Check timedatectl on both machines. A timezone mismatch or NTP not yet synchronized is the most silent cause.
- telnet to 9514 fails to connect: If the configuration is UDP, that is expected. To test UDP use nc -u, or switch to TCP in all three places.
- vector.yaml was changed but has no effect: The configuration is bind-mounted but Vector reads it at startup — run docker compose up -d --force-recreate vector.
Hands-on 4 — Prepare the Kubernetes lab for the next part
40 minutes · optional
The next part of the learning path is Kubernetes. Set up three nodes in advance and finish the groundwork (hostname, timezone, swap, snapshot) so you do not lose time during the hands-on session (Kubernetes: components).
hostnamectl set-hostname k8s-master && timedatectl set-ntp true && swapoff -a
Observe: hostnamectl ; timedatectl ; swapon --show (must be empty) ; ping between the three nodes
1. Create three virtual machines, each with one network card, with a minimum configuration of about 2 vCPU and 4-8 GB RAM. Roles: one control-plane, two workers.
The three machines can reach each other by ping on the same network range.
2. On each machine, set the hostname by role and a static IP according to the plan: hostnamectl set-hostname k8s-master (then k8s-worker1, k8s-worker2).
hostnamectl returns the right name; the names do not collide.
3. Set the timezone and enable NTP sync on all three machines.
timedatectl shows the correct timezone and NTP synchronized is yes on all three.
4. Turn off swap: swapoff -a and remove the swap line in /etc/fstab so it does not come back after reboot.
swapon --show prints nothing, even after a reboot.
5. Shut the machines down, then take a snapshot of all three labeled "base" — the version that already has the IP, hostname and timezone.
You can return to the base version at any time without reconfiguring from scratch.
6. Optional: set up an additional centralized-log node running exactly the VictoriaLogs + Vector stack from this lab, or use the control-plane node itself for that role.
All three nodes can push syslog to the log node — reusing exactly the configuration done in the previous phase.
7. Redraw the lab model yourself, with the IP of each node, and save it along with your lab notes.
The diagram clearly shows each node's role, the network range and the IPs — for quick lookup during an incident.
Analysis
Observation: Most of the time lost when practicing with a cluster goes into setting up the machines, not into cluster knowledge.
Mechanism: A cluster requires unique hostnames, synchronized time and swap off; if any one of the three is missing, the cluster initialization step fails with hard-to-read errors.
Lesson: Finish the groundwork and then snapshot: every retry starts from a known clean state.
Troubleshooting:
- Swap comes back after startup: Running swapoff -a only is temporary. You must comment out or remove the swap line in /etc/fstab.
- Two nodes have the same hostname: Caused by cloning a virtual machine without renaming it. Reset it with hostnamectl, then check /etc/hosts on each machine.
- The nodes cannot ping each other: Check that they are on the same network range and check the firewall. Each node should have only one network card to avoid confusion about routing.
Review questions
Question 1. In a vector.yaml running in a container, which VictoriaLogs address should the sink point to?
- http://127.0.0.1:9428 because the two containers are on the same host
- http://victorialogs:9428 — the service name, resolved through the project network's internal DNS
- http://localhost:9428 because Compose automatically maps localhost between services
- The VictoriaLogs container IP obtained with docker inspect
Answer: http://victorialogs:9428 — the service name, resolved through the project network's internal DNS. Each container has its own network namespace, so its loopback is itself. Services on the same network resolve each other by service name (Compose: networking, VictoriaLogs: Vector setup).
- 127.0.0.1 and localhost inside the Vector container both point at Vector itself. Using the container IP breaks after every recreation because the IP changes.
Question 2. Vector runs in a container, the configuration is valid, the HTTP source works, but no container logs arrive. What is the most likely cause?
- The bind mount /var/run/docker.sock is missing for the vector service
- The docker group permission has not been granted to the user inside the container
- VictoriaLogs does not have retention enabled
- Docker has not changed its log driver to json-file
Answer: The bind mount /var/run/docker.sock is missing for the vector service. The docker_logs source needs Vector to be able to talk to Docker. When Vector runs in a container, that path is the host's Docker socket, so it must be mounted explicitly (Vector: install on Docker).
- Granting permission through the docker group applies to the systemd installation on the host, not to the container version. Retention and the log driver have nothing to do with whether the source can collect.
Question 3. In /etc/rsyslog.conf, what does the line ". @192.0.2.10:9514" mean?
- Send all logs over TCP to 192.0.2.10 port 9514
- Send all logs over UDP to 192.0.2.10 port 9514
- Receive logs from 192.0.2.10 on port 9514
- Write logs to a file on the machine 192.0.2.10
Answer: Send all logs over UDP to 192.0.2.10 port 9514. One @ sign means UDP, two @@ signs mean TCP (rsyslog: actions). This protocol must match the mode declared in Vector's syslog source and the way the port is published in compose.
- TCP needs @@. This line is a forwarding action, not a receiving configuration. And it does not write to a file.
Question 4. The client machine's logs do not appear in the interface even though rsyslog was restarted and reports no errors. What should you check BEFORE opening the firewall?
- Increase VictoriaLogs retention
- Change Docker's log driver
- timedatectl on both machines: the timezone matches and NTP is synchronized
- Restart the whole stack with down and then up
Answer: timedatectl on both machines: the timezone matches and NTP is synchronized. Logs are tied to timestamps: a timezone mismatch or missing NTP sync makes messages arrive but fall outside the time window being viewed, which looks like there are no logs (timedatectl). This is the most silent cause, and checking it is very quick.
- Retention and the log driver are unrelated. Restarting the stack cannot fix a time discrepancy on the sending machine.
Question 5. Why should you run vector validate in a temporary container before docker compose up?
- To download the Vector image beforehand to save time
- To catch Vector configuration errors before any service has been created
- Because compose config cannot read the vector.yaml file
- Because Vector does not check its configuration on startup
Answer: To catch Vector configuration errors before any service has been created. With a bad configuration the service does not start and the error message is buried in the merged log of the whole project. Checking beforehand with a temporary container gives a clean error message, pointing at exactly the misconfigured block, and leaves no container to clean up.
- Downloading the image is only a side effect. compose config does read the mount declarations but does not understand the contents of vector.yaml — they are two different validation layers. Vector does check itself at startup, but by then it is later.
Question 6. After docker compose down and then up -d, can the old logs still be queried, and why?
- No, because down removes the container so the data inside is lost with it
- Yes, because the data lives on the host's ./victoria-logs-data bind mount
- Yes, because VictoriaLogs automatically backs up into a cache
- Only if you had run docker compose stop instead of down
Answer: Yes, because the data lives on the host's ./victoria-logs-data bind mount. The -storageDataPath parameter points at the mount point, and that mount point is a real directory on the host. The data is outside the container lifecycle, so after down and then up -d it can still be queried (Docker: bind mounts).
- Only data in the container's writable layer is lost with the container. There is no automatic backup mechanism, and neither down nor stop deletes a bind mount.
Question 7. Where do the container_name and image labels in the logs on VictoriaLogs come from?
- From being declared in the remap transform of vector.yaml
- From the docker_logs source, which attaches them automatically when collecting logs through Docker
- From VictoriaLogs inferring them from the log content
- From having to set _stream_fields=container_name,image on the uri
Answer: From the docker_logs source, which attaches them automatically when collecting logs through Docker. The docker_logs source receives logs directly through Docker together with the container metadata: name, ID, image (Vector: docker_logs). No extra configuration is needed — that is the advantage over reading log files.
- The transform in this exercise applies only to the HTTP source. VictoriaLogs does not infer metadata from content. _stream_fields only selects which fields identify the stream; it does not create new fields.
Question 8. According to the pragmatic threshold given in the lesson, at what scale is Kubernetes not yet needed?
- Fewer than 3 servers
- Fewer than about 10 servers and an application that is not too large — Docker with Compose is enough
- Only when there is exactly one server
- When there is no need for centralized logging
Answer: Fewer than about 10 servers and an application that is not too large — Docker with Compose is enough. Compose orchestrates on a single host, but good control of volumes and networks already solves most of the problem at this scale, and it is leaner and easier to maintain than a cluster (Kubernetes: components).
- The threshold is not at 3 machines or 1 machine. The need for centralized logging is not a criterion for choosing the orchestration layer — this very exercise builds centralized logging with Compose.
Question 9. Why does the command docker compose exec victorialogs sh always fail?
- Because that service was not declared in the network
- Because the VictoriaLogs image is distroless, with no shell inside
- Because of missing permission on the Docker socket
- Because you must use docker exec instead of docker compose exec
Answer: Because the VictoriaLogs image is distroless, with no shell inside. The image uses a distroless base — only the necessary process, with no shell packaged. That is how the image is designed, not a fault. The fact that Vector sends logs successfully is already proof that internal DNS and networking work.
- The network and socket permissions are unrelated. Switching to docker exec would still fail because there is no shell inside to run.
Flashcards
-
Where does Vector's sink point inside a container? http://victorialogs:9428/insert/jsonline?... — the service name, not an IP or 127.0.0.1. In the Vector container, loopback is itself; services on the same network resolve each other by name.
-
What are the three log sources of Vector in this lesson? http_server on 9000 (JSON from applications) · syslog on 9514/udp (other servers) · docker_logs (every container on the host).
-
What does the docker_logs source need mounted when Vector runs in a container? /var/run/docker.sock to talk to Docker, and /var/lib/docker to read the container log files.
-
What is the risk of mounting the Docker socket into a container? It is equivalent to granting that container control of the whole host's Docker — only do it with a trusted agent.
-
What do the three parameters on the sink's uri mean? _msg_field=message selects the content field, _time_field=timestamp selects the time field, _stream_fields=host,source selects the pair of fields that identify the log stream.
-
What is two-layer validation before up? docker compose config for compose syntax, and a temporary container running vector validate for the Vector configuration.
-
Why do logs survive docker compose down? Because -storageDataPath points at the mount point, and the real directory is ./victoria-logs-data on the host — outside the container lifecycle.
-
rsyslog: what is the difference between one @ and two @@? One @ is UDP, two @@ is TCP. It must match the mode in vector.yaml and the way the port is published in compose.
-
Logs are not arriving — what do you check before opening the firewall? timedatectl on both machines: the timezone matches and NTP is synchronized. A time mismatch makes logs arrive but fall outside the time window being viewed.
-
Where do the container_name/image labels in the logs come from? From the docker_logs source, which attaches them automatically when collecting through Docker — no extra configuration.
-
Why does exec into the VictoriaLogs container always fail? The image uses a distroless base with no shell inside. That is by design, not a fault.
-
When a LogsQL query is empty, what do you check first? Widen the time window and increase the number of displayed rows, before concluding that the logs have not arrived.
-
What is the ceiling of Docker Compose? It only orchestrates on ONE host: if the host dies, every service on that host dies, and it does not move services to another machine by itself.
-
What is the pragmatic threshold below which Kubernetes is not yet needed? Fewer than about 10 servers and an application that is not too large — Docker with Compose is enough, leaner and easier to maintain.
-
What changes in the vocabulary when moving to Kubernetes? service → pod/deployment · volume → PersistentVolume/PersistentVolumeClaim · bridge network → a CNI plugin you must choose yourself · Ingress/Egress added.
-
What is the prerequisite when moving to a cluster? Manifests live in Git with CI/CD from day one — never hand-edited on the servers, because cluster configuration files run to hundreds of lines and are maintained by many people.