No, you can’t. Service names are supposed to be literal strings.
You can use --project-name (short version: -p ) to specify the project name, which will be prefixed to the container, volume, and network names for a particular compose deployment to prevent naming conflicts with other deployments using the same docker-compose.yml
You could render your compose files through templating of some sort (you would need to solve this yourself) and pass it to docker compose, like this: {command to render template} | docker compose -f - up -d
The -f - uses the compose file it receives via stdin.
Somewhere in the forum, I gave an example that uses envsubst for simple templating.