OS: macOS 11.5.2 (20G95)
Docker Desktop 3.6.0 (67351)
Docker is in swarm mode
terminal shell - zsh
docker-compose.yml:
proxy:
image: nginx
networks:
- app_overlay
ports:
- target: 80
published: 80
protocol: tcp
mode: host
nginx config:
http {
server {
listen 80;
server_name localhost;
...
}
server {
listen 80;
server_name web_app.localhost;
...
}
}
/etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
# scutil --dns
#
# SEE ALSO
# dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 192.168.0.1
/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
try to call
curl http://localhost
it runs successfully and displays the html returned by nginx
try to call
curl http://web_app.localhost
get an error:
curl: (6) Could not resolve host: web_app.localhost
autocannon also report about the error in debug mode
Error: getaddrinfo ENOTFOUND web_app.localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'web_app.localhost'
}
but browsers correctly resolve the hostname and display the application page