我需要为容器创建一个本地 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