Nginx with Docker Compose can not resolve his own name (hostname.domainname)

I have a fixed menu image containing a NGINX server. I run it in a docker-composed file like this:

version: 2.1 & # 39;

services:
dev.example.com:
# etc.

If I adjust the resolver to use the Docker one in NGINX, so I can refer to dev.example.com from the rest of the configuration and it is set to the correct IP address:

http {
resolver 127.0.0.11;
}

However, I would prefer not to name the service dev.example.comand use instead host name and domain name in docker-compose:

version: 2.1 & # 39;

services:
Proxy:
domain name: example.com
hostname: dev
# etc.

This would allow me to use environment variables to control the hostname. The problem is that when I use these settings instead of the service name, NGINX can not resolve it anymore. dev.example.com, even if the basic tests with ping, loop etc. from the current container, solve it correctly.

How can I configure the domain / hostname dynamically without changing the name of the service, in a manner compatible with NGINX?