![如何在另一个 docker 容器中使用 dnsmasq 作为 DNS 服务器?](https://linux22.com/image/790488/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%8F%A6%E4%B8%80%E4%B8%AA%20docker%20%E5%AE%B9%E5%99%A8%E4%B8%AD%E4%BD%BF%E7%94%A8%20dnsmasq%20%E4%BD%9C%E4%B8%BA%20DNS%20%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9F.png)
我需要为容器创建一个本地 DNS 服务器,用于白名单域地址。
dnsmasq配置文件
port=53
domain-needed
bogus-priv
bind-interfaces
no-resolv
strict-order
server=/google.com/8.8.8.8
server=/google.com/8.8.4.4
server=/github.com/8.8.8.8
server=/github.com/8.8.4.4
server=/api.github.com/8.8.8.8
server=/api.github.com/8.8.4.4
docker-compose.yml
version: '3.8'
services:
dns-server:
restart: always
image: strm/dnsmasq
container_name: dnsmasq
volumes:
- ./dnsmasq.conf:/etc/dnsmasq.conf
ports:
- "53:53/udp"
cap_add:
- NET_ADMIN
networks:
- "custom-dns"
test-dns:
container_name: test-dns
image: nginx:latest
networks:
- "custom-dns"
dns: dns-server
networks:
custom-dns: {}
我试过DNS:test-dns
“dns-server”、“127.0.0.1”、“172.17.0.1”但在命令curl google.com
结果 后的容器中不起作用curl: (6) Could not resolve host: google.com