Nginx logs when filebeat and nginx both are running in containers

I am running filebeat and nginx in different containers.

nginx is writing logs in a custom path within the container:

My compose and filebeat configs:

filebeat is not able to read logs. Even i am not able to think how it works.

How attaching /var/lib/docker/containers:/var/lib/docker/containers:ro makes sure that file is read?

Need help in understanding how container input works and how it gets inside another containers filesystem