Compose puts labels on every container it creates, such as the project and the service name. Plain docker commands can filter on them, so you can find a project’s containers from any folder.
docker ps --filter label=com.docker.compose.project=media \
--format 'table {{.Names}}\t{{.Label "com.docker.compose.service"}}\t{{.Status}}'
That lists the containers of the media project with their service name and status. Other labels that are there: com.docker.compose.service, com.docker.compose.project.working_dir (the folder the project lives in) and com.docker.compose.project.config_files.
The working directory label is my favourite. When you find an old container and wonder which Compose file started it, this tells you:
docker inspect --format '{{index .Config.Labels "com.docker.compose.project.working_dir"}}' mycontainer
You can add your own labels too, with labels: in Compose or -l on docker run, and filter on them the same way.
These labels are set by Compose for its own bookkeeping. Do not edit or copy them onto containers made by other tools, because Compose uses them to decide which containers belong to a project and may stop or remove the wrong one.
Further reading: docker container ls: filtering, Docker object labels