¿Cómo puedo configurar mi máquina local para usar un servidor DNS alojado en Docker junto con otras configuraciones de DNS para dominios específicos?

¿Cómo puedo configurar mi máquina local para usar un servidor DNS alojado en Docker junto con otras configuraciones de DNS para dominios específicos?

Tengo el siguiente docker-compose.yml usado como solución local de aplicación web php:

version: "3.1"

services:
  nginx:
    image: nginx:1.13
    volumes:
      - "./configuration/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./configuration/etable-local.key:/etc/nginx/etable-local.key:ro"
      - "./configuration/etable-local.crt:/etc/nginx/etable-local.crt:ro"
      - "website:/var/www/html/website"
      - "api:/var/www/html/static"
    links:
      - "php708:website"
      - "php72:api"
    networks:
      frontend:
        ipv4_address: 172.20.0.5
    ports:
      - "80:80"
      - "443:443"

  php72:
    image: php:7.2-fpm-alpine
    volumes:
      - "api:/var/www/html/api"
    environment:
      ENVIRONMENT: local
    networks:
      - frontend
    dns:
      - 8.8.8.8
      - 9.9.9.9
  website:
    image: php:7.2-fpm-alpine
    volumes:
      - "api:/var/www/html/api"
    environment:
      ENVIRONMENT: local
    networks:
      - frontend
    dns:
      - 8.8.8.8
      - 9.9.9.9
volumes:

  website:
    driver: local
    driver_opts:
      type: "none"
      o: "bind"
      device: $WEBSITE_DIR

  api:
    driver: local
    driver_opts:
      type: "none"
      o: "bind"
      device: $API_DIR

networks:
  frontend:
    ipam:
      config:
        - subnet: 172.20.0.0/24

Y en mi computadora que ejecuta el contenedor acoplable tengo las siguientes entradas en /etc/hosts:

172.20.0.5 api.local
172.20.0.5 website.local

Pero también quiero ofrecer dominios comodín, por lo tanto, estoy pensando en enviar también un dnsmasq con las configuraciones apropiadas en mi docker-compose y deshacerme por completo /etc/hosts(mejor reutilización y configuración compartida entre el equipo):

version: "3.1"

services:
  nginx:
    image: nginx:1.13
    volumes:
      - "./configuration/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./configuration/etable-local.key:/etc/nginx/etable-local.key:ro"
      - "./configuration/etable-local.crt:/etc/nginx/etable-local.crt:ro"
      - "website:/var/www/html/website"
      - "api:/var/www/html/static"
    links:
      - "php708:website"
      - "php72:api"
    networks:
      frontend:
        ipv4_address: 172.20.0.5
    ports:
      - "80:80"
      - "443:443"

  php72:
    image: php:7.2-fpm-alpine
    volumes:
      - "api:/var/www/html/api"
    environment:
      ENVIRONMENT: local
    networks:
      - frontend
    dns:
      - 8.8.8.8
      - 9.9.9.9

  website:
    image: php:7.2-fpm-alpine
    volumes:
      - "api:/var/www/html/api"
    environment:
      ENVIRONMENT: local
    networks:
      - frontend
    dns:
      - 8.8.8.8
      - 9.9.9.9

  dnsmasq:
     image: 'jpillora/dnsmasq'
     ports:
      - "53:53/udp" 
      - "5380:8080"
    volumes:
       -"/opt/dnsmasq.conf:/etc/dnsmasq.conf"
    environment:
        HTTP_USER: foo
        HTTP_PASS: bar
    networks:
      frontend:
        ipv4_address: 172.20.0.6
    dns:
      - 8.8.8.8
      - 9.9.9.9

volumes:

  website:
    driver: local
    driver_opts:
      type: "none"
      o: "bind"
      device: $WEBSITE_DIR

  api:
    driver: local
    driver_opts:
      type: "none"
      o: "bind"
      device: $API_DIR

networks:
  frontend:
    ipam:
      config:
        - subnet: 172.20.0.0/24

Pero, ¿cómo puedo configurar mi máquina GNU/Linux local y Windows para resolver los dominios apropiados junto 172.20.0.6con cualquier otro dominio?

En mi Linux Mint 19.04, una vez que ejecuto ifconfig obtengo la siguiente configuración:

br-144546484da6: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        ether 02:42:ee:ad:b4:6b  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br-2c821d16ac40: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.24.0.1  netmask 255.255.0.0  broadcast 172.24.255.255
        ether 02:42:d1:29:8f:d0  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br-936b043d07ec: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.1  netmask 255.255.255.0  broadcast 172.20.0.255
        inet6 fe80::42:31ff:fe3b:6a93  prefixlen 64  scopeid 0x20<link>
        ether 02:42:31:3b:6a:93  txqueuelen 0  (Ethernet)
        RX packets 21190  bytes 46944301 (46.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20152  bytes 3393362 (3.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:63:fa:1e:98  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.4  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::4819:e008:32b3:eb75  prefixlen 64  scopeid 0x20<link>
        ether 30:5a:3a:82:3c:2c  txqueuelen 1000  (Ethernet)
        RX packets 1020236  bytes 974038110 (974.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 708231  bytes 83763973 (83.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 35856  bytes 3871878 (3.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 35856  bytes 3871878 (3.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vboxnet3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.1  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::800:27ff:fe00:3  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:03  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1537  bytes 248272 (248.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth15937a1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::f828:5eff:fe17:5f3f  prefixlen 64  scopeid 0x20<link>
        ether fa:28:5e:17:5f:3f  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1299  bytes 200892 (200.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth4f39177: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7807:8bff:fef4:90d6  prefixlen 64  scopeid 0x20<link>
        ether 7a:07:8b:f4:90:d6  txqueuelen 0  (Ethernet)
        RX packets 4022  bytes 2287668 (2.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4674  bytes 1238082 (1.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethb2863e3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::986d:2aff:feae:5a83  prefixlen 64  scopeid 0x20<link>
        ether 9a:6d:2a:ae:5a:83  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1279  bytes 197402 (197.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethe23b637: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::d8cf:8dff:fe79:2de  prefixlen 64  scopeid 0x20<link>
        ether da:cf:8d:79:02:de  txqueuelen 0  (Ethernet)
        RX packets 10344  bytes 1065309 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11282  bytes 1252992 (1.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethea02dde: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::a8aa:72ff:fe3f:f7f6  prefixlen 64  scopeid 0x20<link>
        ether aa:aa:72:3f:f7:f6  txqueuelen 0  (Ethernet)
        RX packets 1792  bytes 43279416 (43.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2443  bytes 307732 (307.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf1bdbae: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::6cd3:dfff:feec:1000  prefixlen 64  scopeid 0x20<link>
        ether 6e:d3:df:ec:10:00  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1272  bytes 196493 (196.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf209ff2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7c6c:11ff:fecc:25c7  prefixlen 64  scopeid 0x20<link>
        ether 7e:6c:11:cc:25:c7  txqueuelen 0  (Ethernet)
        RX packets 5594  bytes 45271086 (45.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7041  bytes 45379695 (45.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Y la red que ejecuta dns es: br-936b043d07ecpero me temo que su nombre también puede cambiar cada vez que ejecuto docker-compose up(una vez que termino mi trabajo, ejecuto con frecuencia docker-compose down).

Muchas soluciones como esta.unosugerir resolución DNSADENTROcontenedor acoplable. Y esto no es lo que quiero, sino una forma de tener una resolución de nombres comodín de una manera similar en la que podría configurar dominios locales en /etc/hosts.

información relacionada