# Docker - logging the container id

**URL:** https://discuss.elastic.co/t/docker-logging-the-container-id/139831
**Category:** Beats
**Tags:** filebeat
**Created:** [July 12, 2018, 8:29pm UTC](https://discuss.elastic.co/t/docker-logging-the-container-id/139831 "2018-07-12T20:29:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tallavi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallavi/32/73613_2.png) [@tallavi](https://discuss.elastic.co/u/tallavi)
#### Post date: [July 12, 2018, 8:29pm UTC](https://discuss.elastic.co/t/docker-logging-the-container-id/139831/1 "2018-07-12T20:29:07Z")

</div>

Hi,

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:

labels:  
env: "PROD"  
service: "my-service"  
logging:  
driver: "json-file"  
options:  
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?

Thanks,

Tal

---

<div class="post-metadata">

### Author: ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)
#### Post date: [July 13, 2018, 7:34am UTC](https://discuss.elastic.co/t/docker-logging-the-container-id/139831/2 "2018-07-13T07:34:30Z")

</div>

`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.

---

<div class="post-metadata">

### Author: ![tallavi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tallavi/32/73613_2.png) [@tallavi](https://discuss.elastic.co/u/tallavi)
#### Post date: [July 13, 2018, 12:27pm UTC](https://discuss.elastic.co/t/docker-logging-the-container-id/139831/3 "2018-07-13T12:27:02Z")

</div>

> [@ruflin](#):
>
> `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.

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!

Tal

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 10, 2018, 12:27pm UTC](https://discuss.elastic.co/t/docker-logging-the-container-id/139831/4 "2018-08-10T12:27:02Z")

</div>

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