“Services” created via docker compose are containers that are connected via a docker custom network. Containers thus connected use Docker’s embedded DNS server, which resolves container names and aliases itself, and forwards all other lookups to DNS servers configured on the host. This is documented in the first paragraph here. Service names are aliases for the respective containers.
Thus, a service name will always resolve before an external DNS entry.