Any way to tell where a file in overlay2 is used?

I couldn’t resist: I created a docker-compose stack that deploys a container as global service, queries the details from all containers on the node and then terminates the container on the node. Make sure to wait until each task of the stack is completed before your fetch the logs and delete the stack.

docker-compose.yml:

version: '3.7'
services:
  inventory:
    image: docker
    deploy:
      mode: global
      restart_policy:
        condition: none
    volumes:
    -  /var/run/docker.sock:/var/run/docker.sock
    environment:
      NODE_HOSTNAME: '{{.Node.Hostname}}'
    entrypoint: >
      sh -c "for container in $$(docker ps --all --quiet --format '{{ .Names }}'); do \
        echo \"$$(docker inspect $$container --format '{{.GraphDriver.Data.MergedDir }}' | sed 's#/\([^az]*\)\.*$$##' ) = $$NODE_HOSTNAME.$$container\" ;\
      done"