Dynamically resolving a container name using shell script

I’m currently working on docker development environments for multiple projects. I’m struggling with resolving docker container names dynamically. I made the following shell script to resolve a container name;

# Resolve container with a suffix of -php
CONTAINER=$(docker-compose ps | grep -e -php | awk '{print $1;}')

if [ -z "$CONTAINER" ]
  echo "Could not resolve the php container, exiting."

There are multiple containers running (in different projects) with a suffix of -php. I have to resolve the container inside the current project.

Source: StackOverflow