一旦运行 docker-compose up,如何提供仅本地的域解析?

一旦运行 docker-compose up,如何提供仅本地的域解析?

我有以下docker-compose:

version: "3.1"

services:
  nginx:
    image: nginx
  networks:
    frontend:
      ipv4_address: 172.20.0.5
    outgoing:
      ipv4_address: 172.20.1.5
  volumes:
    - "./configuration/nginx.conf:/etc/nginx/nginx.conf:ro"
    - "./configuration/service-local.key:/etc/nginx/service-local.key:ro"
    - "./configuration/service-local.crt:/etc/nginx/service-local.crt:ro"
    - "website:/var/www/html/website"
    - "api:/var/www/html/api"
  extra_hosts:
    - "api:172.20.0.3"
    - "website:172.20.0.4"

  api:
    image: php
      volumes:
        - "api:/var/www/html/api"
      networks:
        - frontend
      extra_hosts:
        - "api.local:172.20.0.5"
      dns:
        - 8.8.8.8
        - 9.9.9.9
      networks:
        frontend:
          ipv4_address: 172.20.0.3
  
  website:
    image: php
      volumes:
        - "api:/var/www/html/api"
      networks:
        - frontend
      extra_hosts:
        - "api.local:172.20.0.5"
      dns:
        - 8.8.8.8
        - 9.9.9.9
      networks:
        frontend:
          ipv4_address: 172.20.0.4
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:
  backend:
    ipam:
      config:
        - subnet: 172.20.0.0/24

  frontend:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.20.1.0/24

所有传入流量都将通过frontend流量。上述设置用于我在本地机器上进行应用程序开发。

对于开发,我们使用以下主机名直接放置在每个开发人员的/etc/hosts每个文件中:hosts

  • api.local对于在api容器中执行的api。
  • website.localwebsite对于在容器中执行的实际网站。

此外,我还有一个 Android 应用,我使用它来测试使用上述域名的移动应用。我如何在每个开发人员的机器上为特定网络中的应用提供某种 DNS?

相关内容