Điểm:0

How I can configure my local machine to use a docker hosted dns server alonsside with ant other dns settings for specific domains?

lá cờ fr

I have the following docker-compose.yml used as php web app local solution:

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

And in my computer that run the docker container I have the following entries in /etc/hosts:

172.20.0.5 api.local
172.20.0.5 website.local

But I also want to serve wildcard domains, therefore I am thinking to also ship a dnsmasq as well with the appropriate configs in my docker-compose and ditch completely the /etc/hosts (better reusability and shared settings accross team):

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

But how I can configure my local GNU/Linux machine and Windows to resolve the apprpriate domains via 172.20.0.6 alongside with any other domain?

In my linux mint 19.04 once I run ifconfig I get the following settings:

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

And the network that dns is running is the: br-936b043d07ec but I am afraid that its name may change as well every time that I run docker-compose up (once I finish my job I frequently run docker-compose down).

Many solutions such as this one suggest dns resolution INSIDE docker container. ans this is not what I want but a way to have wildcard name resolution in a similar fashion I could setup local domains in /etc/hosts.

Đăng câu trả lời

Hầu hết mọi người không hiểu rằng việc đặt nhiều câu hỏi sẽ mở ra cơ hội học hỏi và cải thiện mối quan hệ giữa các cá nhân. Ví dụ, trong các nghiên cứu của Alison, mặc dù mọi người có thể nhớ chính xác có bao nhiêu câu hỏi đã được đặt ra trong các cuộc trò chuyện của họ, nhưng họ không trực giác nhận ra mối liên hệ giữa câu hỏi và sự yêu thích. Qua bốn nghiên cứu, trong đó những người tham gia tự tham gia vào các cuộc trò chuyện hoặc đọc bản ghi lại các cuộc trò chuyện của người khác, mọi người có xu hướng không nhận ra rằng việc đặt câu hỏi sẽ ảnh hưởng—hoặc đã ảnh hưởng—mức độ thân thiện giữa những người đối thoại.