【问题标题】:Port mapping in docker container with multiple networks具有多个网络的 docker 容器中的端口映射
【发布时间】:2021-09-21 11:17:22
【问题描述】:

多次使用docker,熟悉docker网络和端口映射的概念。但是,我还没有在网上找到任何你想混合这两者的案例。希望有好心人帮帮我。

我在很多情况下都使用 Traefik。我也有 pi-hole 软件作为私有 DNS。我想标准化 Traefik 背后的所有服务以使用 TLS 和自定义(内部)域。 pi-hole 管理界面与 Traefik 完美配合。

边缘路由器后面的 pi-hole 的最大问题是 docker 使用 NAT 作为内部网络。因此 pi-hole 无法查看 DNS 请求的来源。唯一要克服的就是将 DNS 端口(53 和 853)直接映射到主机,我猜(所以绕过内部 Traefik 网络,绕过任何 NAT)。

我可以将 pi-hole 容器附加到多个网络,但我如何能够将 :80 附加到 Traefik 网络并将 :53 附加到主机网络?

【问题讨论】:

    标签: docker traefik pihole


    【解决方案1】:

    最终这很简单,尽管我认为这不会奏效:只需在 pi-hole 容器连接到 Traefik 网络时发布端口。

    这是我使用的 Ansible 配置:

    - name: Create the pihole container
      docker_container:
        name: "{{ pihole_docker_container }}"
        image: "{{ pihole_docker_tag }}"
        pull: yes
        restart_policy: unless-stopped
        networks_cli_compatible: yes
        networks:
          - name: "{{ traefik_docker_network }}"
        volumes:
          - "{{ pihole_config_dir }}:/etc/pihile/"
          - "{{ pihole_dnsmasq_dir }}:/etc/dnsmasq.d/"
        env:
          TZ: "{{ pihole_tz }}"
          WEBPASSWORD: ""
          DNS1: "{{ pihole_container_dns1 }}"
          DNS2: "{{ pihole_container_dns2 }}"
          REV_SERVER: "{{ pihole_server_rev }}"
          REV_SERVER_DOMAIN: "{{ pihole_server_domain }}"
          REV_SERVER_TARGET: "{{ pihole_server_gateway }}"
          REV_SERVER_CIDR: "{{ pihole_server_subnet }}"
        dns_servers:
          - 127.0.0.1
          - "{{ pihole_container_dns1 }}"
        ports:
          - "53:53/tcp"
          - "53:53/udp"
          - "853:853"
        labels:
          traefik.enable: "true"
    
          traefik.http.routers.pihole.entrypoints: "websecure"
          traefik.http.routers.pihole.rule: "Host(`{{ pihole_public_domain }}`)"
          traefik.http.routers.pihole.middlewares: "pihole-admin"
          traefik.http.routers.pihole.service: "pihole"
          traefik.http.routers.pihole.tls: "true"
          traefik.http.routers.pihole.tls.certresolver: "le"
    
          traefik.http.middlewares.pihole-admin.addprefix.prefix: "/admin"
    
          traefik.http.routers.pihole_http.entrypoints: "web"
          traefik.http.routers.pihole_http.rule: "Host(`{{ pihole_public_domain }}`)"
          traefik.http.routers.pihole_http.middlewares: "redirect-to-https"
    
          traefik.http.services.pihole.loadBalancer.server.port: "80"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 2017-03-30
      • 2017-08-02
      相关资源
      最近更新 更多