Name resolution not working with docker containers

I have installed HAproxy on two vagrant VM in virtualbox (both debian buster, on bridged network connection) and has setup (installed on the VM) keepalived to manage a single VIP. I am running two nginx docker containers on each machine. When I use the IP address for the ‘backend’ everything works as it should.
When I use the hostname of the container HAproxy says

Nov 16 21:12:05 buster haproxy[24426]: [ALERT] 320/211205 (24426) : parsing [/etc/haproxy/haproxy.cfg:48] : 'server server1' : could not resolve address 'nginx1'.
Nov 16 21:12:05 buster haproxy[24426]: [ALERT] 320/211205 (24426) : parsing [/etc/haproxy/haproxy.cfg:49] : 'server server2' : could not resolve address 'nginx2'.

Docker setup

docker network create web-net
docker run --name nginx1 --hostname nginx1 --network web-net -d nginxdemos/hello
docker run --name nginx2 --hostname nginx2 --network web-net -d nginxdemos/hello

HAproxy configuration

    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy

    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

resolvers docker
    nameserver dns

frontend http-in
    bind    # VIP
    default_backend servers

backend servers
    balance roundrobin
    server server1 nginx1:8080 check resolvers docker resolve-prefer ipv4
    server server2 nginx2:8080 check resolvers docker resolve-prefer ipv4

If I put the IP address of the nginx containers, instead of name then everything is fine.
Can someone point me why the name resolution is not working correctly ? I tried the docker interface address. Any point to debug it correctly ?

Thank you.