Docker - logging the container id

(Tal Lavi) #1


I'm running filebeat 6.3 as a container on my machine, watching /var/lib/docker/containers//.log (mapped as a volume), and collecting all the logs of all the containers in that machine.

In order to distinguish between the different containers, I add labels to each containers, and make sure they are logged. For example:

env: "PROD"
service: "my-service"
driver: "json-file"
labels: "env,service"

This makes the fields pop in the log line, under attrs. What I'm missing, is a way to have a label for the container id, so I can distinguish between different containers of the same kind. Is there a way to add it to the log?

I tried add_docker_metadata but it doesn't seem to work - probably because filebeats is inside a container and not on the host?



(ruflin) #2

add_docker_metadata is the right tool to use here. You must make sure that your container has access to the docker socker so probably mount it as volume into your container.

(Tal Lavi) #3

Thanks, I tried it before and it didn't work, but with the renewed confidence that docker_metadata should work even when inside a container, I managed to find a configuration that works. Now it's great!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.