[英]Port mapping in docker container with multiple networks
Having used docker on multiple occasions, I am familiar with the concepts of docker networks and port mapping.多次使用docker,熟悉docker网络和端口映射的概念。 However, I haven't found any case online where you'd want to mix those two.
但是,我还没有在网上找到任何你想要混合这两者的案例。 Hopefully there are ppl who can help me out.
希望有能帮帮我的人。
I use Traefik in many situations.我在很多情况下都使用 Traefik。 I also have pi-hole software as private DNS.
我也有 pi-hole 软件作为私有 DNS。 I would like to standardize all services behind Traefik to use TLS and custom (internal) domains.
我想标准化 Traefik 背后的所有服务以使用 TLS 和自定义(内部)域。 The pi-hole admin interface works perfectly together with Traefik.
pi-hole 管理界面与 Traefik 完美配合。
The biggest issue with pi-hole behind an edge router, is docker uses NAT for the internal network.边缘路由器后面的 pi-hole 的最大问题是 docker 将 NAT 用于内部网络。 So pi-hole is not able to see where the DNS requests are made from.
因此 pi-hole 无法查看 DNS 请求的来源。 The only thing to overcome this is to map the DNS ports (53 & 853) directly to the host, I guess (so bypassing the internal Traefik network, bypassing any NAT).
我想唯一可以克服的就是将 DNS 端口(53 和 853)直接映射到主机(因此绕过内部 Traefik 网络,绕过任何 NAT)。
I can attach the pi-hole container to multiple networks, but how I'm able to attach :80
to the Traefik network and :53
to the host network?我可以将 pi-hole 容器附加到多个网络,但是如何将
:80
附加到 Traefik 网络,将:53
附加到主机网络?
Eventually this was quite simple, although I didn't think this would work: simply publish the ports while the pi-hole container is connected to the Traefik network.最终这很简单,尽管我认为这行不通:只需在 pi-hole 容器连接到 Traefik 网络时发布端口。
This is the Ansible config I used:这是我使用的 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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.