Dnsmasq needs an upstream server to resolve the DNS queries. That upstream server can be anything, Google, Cloudflate, Quad9, or, a local Unbound instance.
You run an unbound server with a static IP, and point dnsmasq to said static IP.
OPs setup has this configured through Pi-hole. Look at the docker-compose file.
Anyway, regardless, you can use dnsmasq with Unbound.