Consul agent not resolving inside ubuntu docker container

I am running a Ubuntu 22 container with --network host with dnsmasq installed. Dig with explicit dns server and port works not without it. I have added "nameserver" to resolv.conf and added 10-consul entry in dnsmasq. Consul servers are not running on docker, they are running on other VMs.

dig @ -p 8600 consul.service.consul

; <<>> DiG 9.18.1-1ubuntu1.3-Ubuntu <<>> @ -p 8600 consul.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64555
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

; EDNS: version: 0, flags:; udp: 1232
;consul.service.consul.         IN      A

consul.service.consul.  0       IN      A       Consul_Server1
consul.service.consul.  0       IN      A       Consul_Server2
consul.service.consul.  0       IN      A       Consul_Server3

;; Query time: 2 msec
;; WHEN: Tue Mar 07 11:42:29 UTC 2023
;; MSG SIZE  rcvd: 98

root@server:/home/postgres# dig consul.service.consul

; <<>> DiG 9.18.1-1ubuntu1.3-Ubuntu <<>> consul.service.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 61564
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

; EDNS: version: 0, flags:; udp: 4096
;consul.service.consul.         IN      A

;; Query time: 0 msec
;; WHEN: Tue Mar 07 11:42:35 UTC 2023
;; MSG SIZE  rcvd: 50

consul members
Node         Address             Status  Type    Build   Protocol  DC   Partition  Segment
server1 IP1:8301  alive   server  1.15.0  2         dc1  default    <all>
server2 IP2:8301  alive   server  1.15.0  2         dc1  default    <all>
server3 IP3:8301  alive   server  1.15.0  2         dc1  default    <all>
agent1 IP4:8301  alive   client  1.15.0  2         dc1  default    <default>

Edit: updating container/host details

Container Info:

Description:    Ubuntu 22.04.2 LTS
Consul : Consul v1.15.0
Revision 53f65dc3
Build Date 2023-02-24T01:39:35Z
Dnsmasq installed: 

Host Info:

OS: Oracle Linux Server release 7.9
Dnsmasq installed: 

Hello. Welcome to these forums - unfortunately, due to the low level of detail in you post, it is unlikely anyone will be able to assist, unless you provide a lot of clarification…

Well… actually there’s no such thing as “Ubuntu 22”. There’s “Ubuntu 22.04” and “Ubuntu 22.10” but those are entirely separate versions. They’re also just derived from date codes referring to April 2022 and October 2022 and are no more closely related to each other than adjacent Ubuntu versions released in different years.

You mean port, not post, right? Sure, that sounds as expected.

You’ve mentioned --network host, but not explained what the host system is.

Since there’s a host system involved, it’s also ambiguous whether your dnsmasq is running in the container or the host system.

It’s also possible there might already be another DNS listener running on the host system.

You’ve mentioned changing the dnsmasq configuration, but not provided any details about what you changed it to.

Updated info. Basically, what we want to do is use bridge networking instead of host to run a docker container with Consul agent and be able to connect to consul server cluster running on a different VM(no docker on consul server cluster).

it was an issue with dnsmasq. installed dnsmasq on host and had to add changes to resolv.conf inside container. This fixed the issue