Bind9 container in docker giving communication error

I am trying to setup a local DNS server in ubuntu using this tutorial.

https://blog.yarsalabs.com/bind9-dns-server-setup-in-docker/

this is my docker run command:

docker run -d -p 1153:53/tcp -p 1153:53/udp -p 127.0.0.1:953:953/tcp --rm --name=dns-master --net=labnet --ip=192.168.0.2 

However, when I try to query the DNS server, it says communication error.

Dockerfile

#Base Bind9 Image

FROM internetsystemsconsortium/bind9:9.18

RUN apt update \
  && apt install -y \
  bind9-doc \
  bind9-dnsutils \
  bind9-host \
  libedit2 \
  dnsutils \
  geoip-bin \
  mariadb-server \
  net-tools

# Copy configuration files
COPY configuration/named.conf.options /etc/bind/
COPY configuration/named.conf.local /etc/bind/
COPY configuration/db.vishnu /etc/bind/zones/

# Expose Ports
EXPOSE 53/tcp
EXPOSE 53/udp
EXPOSE 953/tcp

# Start the Name Service
CMD ["/usr/sbin/named", "-g", "-c", "/etc/bind/named.conf", "-u", "bind"]

zone file: db.vishnu

$TTL    1d ; default expiration time (in seconds) of all RRs without their own TTL value
@       IN      SOA     ns1.vishnu. root.vishnu. (
                  3      ; Serial
                  1d     ; Refresh
                  1h     ; Retry
                  1w     ; Expire
                  1h )   ; Negative Cache TTL

; name servers - NS records
     IN      NS      ns1.vishnu.

; name servers - A records
ns1.vishnu.             IN      A      192.168.0.1
one.vishnu.             IN      A      192.168.1.1
two.vishnu.             IN      A      192.168.1.2

named.conf.local

zone "vishnu" {    
    type master;    
    file "/etc/bind/zones/db.vishnu";

not sure, where am I missing. pointers please.

What is your subnet? You can’t assign just any ip address to the container if it is outside of your docker network subnet. I guess that should also throw an error, but the error message clearly says the ip address is not available. It looks like your host network is probably in the same subnet. It would work only if your docker network was a macvlan or ipvlan. And in case of macvlan the host would not be able to communicate with the container without some extra network config on the host.

Please, show the output of the following commands:

docker inspect labnet

and

docker inspect dns-master

$ docker inspect dns-master
[
    {
        "Id": "4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a",
        "Created": "2024-07-04T07:46:22.216432948Z",
        "Path": "/usr/sbin/named",
        "Args": [
            "-g",
            "-c",
            "/etc/bind/named.conf",
            "-u",
            "bind"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 13024,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2024-07-04T07:46:24.669298185Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:efbb2f80df94a8b1717a2d82042546997057c0446cd2e6df7615ac861462a9e1",
        "ResolvConfPath": "/var/lib/docker/containers/4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a/hostname",
        "HostsPath": "/var/lib/docker/containers/4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a/hosts",
        "LogPath": "/var/lib/docker/containers/4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a/4e9b9abcf8bce38df021cf1f59d7cd415a9485191dc3aa82517aa9214f352e0a-json.log",
        "Name": "/dns-master",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "labnet",
            "PortBindings": {
                "53/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "1153"
                    }
                ],
                "53/udp": [
                    {
                        "HostIp": "",
                        "HostPort": "1153"
                    }
                ],
                "953/tcp": [
                    {
                        "HostIp": "127.0.0.1",
                        "HostPort": "953"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": true,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                55,
                204
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": null,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/e971915b95a30028fb5ad4d95c7265ab4ede2a72b97705610ced35e578124f82-init/diff:/var/lib/docker/overlay2/3cc8d6918fa2bfa96d18db892adf46054c557abd55717a7a3ceb52585838de8a/diff:/var/lib/docker/overlay2/d576098e4cc6bf286655fc1119b2a343e180d482734d317de69e07ab1a8c6fa6/diff:/var/lib/docker/overlay2/161d21931b4c57226d9c50a59e4f8939a12f2b71820ff11a607dfc1561f83a58/diff:/var/lib/docker/overlay2/3cd011192c37bf706bb4f8ea94dd11ede861506446afcfe97d6a03c6ace52dec/diff:/var/lib/docker/overlay2/98ef258a70431725b41168c6baa9b9ed551a82a174584faf38fc241c8093de20/diff:/var/lib/docker/overlay2/6d126f8962e3f5f64404cc77f85e8c879054377f1f31f8dd949dec5ef3ae9581/diff:/var/lib/docker/overlay2/43a3040da1e9a381eaae534c3206b5bbc0460371900a47fd92edd2d8cf161fb1/diff:/var/lib/docker/overlay2/c593d9e326a0160c5bbf3435b3471056108dfae5223ddc98592168d2f9da0c15/diff:/var/lib/docker/overlay2/c4f809c1b1648056d557eef5ef79f0cd324c0922eee01363ce7ae05f779a02ed/diff:/var/lib/docker/overlay2/5e396dc43f1d6512e95308a98c49801ea8a44d7acbb0d52c64051e1ef800ba31/diff:/var/lib/docker/overlay2/bfa6cc23b3a647f51717a086dbf1a2f4737fc2373cb99a40732670a8ba54dcc5/diff:/var/lib/docker/overlay2/149f1e497461f4375dcc31ecd214a3f5385ea922ce6848a4ec8b261e46bff1bb/diff:/var/lib/docker/overlay2/1ed5856e55c868acc1b2e43c4ae3885c81dc3357e0940e934bc7f9aaeedf70f8/diff:/var/lib/docker/overlay2/769107d172451378fb08a85877ab37d23ffa1dfcbbae597ce259fff14196dcc6/diff:/var/lib/docker/overlay2/6852a750dd2bee5d713afc60f01c76bf0caaf98b6bec8eea87f910efceb7e63a/diff:/var/lib/docker/overlay2/da64280ad7a18fb49352f79da4054972c7eea334209442b639d97c4bd9309427/diff:/var/lib/docker/overlay2/d219b97d467b2f3dbff20f0daf1ed6c4bb1178f3b44f4972fc86fc12a916261c/diff:/var/lib/docker/overlay2/85fa854d663b3c70e9c6dc6151a521832e38e57821e416835e4aff7120579f16/diff",
                "MergedDir": "/var/lib/docker/overlay2/e971915b95a30028fb5ad4d95c7265ab4ede2a72b97705610ced35e578124f82/merged",
                "UpperDir": "/var/lib/docker/overlay2/e971915b95a30028fb5ad4d95c7265ab4ede2a72b97705610ced35e578124f82/diff",
                "WorkDir": "/var/lib/docker/overlay2/e971915b95a30028fb5ad4d95c7265ab4ede2a72b97705610ced35e578124f82/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "703e8f54ff3edddab269af43bd59cf4463ccf918099565d5e3dd7d7cd4d3a9ae",
                "Source": "/var/lib/docker/volumes/703e8f54ff3edddab269af43bd59cf4463ccf918099565d5e3dd7d7cd4d3a9ae/_data",
                "Destination": "/etc/bind",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "3b0c62f64c202a2fa9add2b230e5c7a1b5c9642f5706b818534387951dc1a793",
                "Source": "/var/lib/docker/volumes/3b0c62f64c202a2fa9add2b230e5c7a1b5c9642f5706b818534387951dc1a793/_data",
                "Destination": "/var/cache/bind",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "ca5d9765d8ce8da689eb12d7274fd9d903cbc556ebc4a6e50d5fa6ecc0dfce40",
                "Source": "/var/lib/docker/volumes/ca5d9765d8ce8da689eb12d7274fd9d903cbc556ebc4a6e50d5fa6ecc0dfce40/_data",
                "Destination": "/var/lib/bind",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "84123163e2146f85215b1012d4ace7acd2bdf9c9bb261e171d89081186b2a0c0",
                "Source": "/var/lib/docker/volumes/84123163e2146f85215b1012d4ace7acd2bdf9c9bb261e171d89081186b2a0c0/_data",
                "Destination": "/var/log",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "4e9b9abcf8bc",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "53/tcp": {},
                "53/udp": {},
                "953/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DEBIAN_FRONTEND=noninteractive",
                "LC_ALL=C.UTF-8"
            ],
            "Cmd": [
                "/usr/sbin/named",
                "-g",
                "-c",
                "/etc/bind/named.conf",
                "-u",
                "bind"
            ],
            "Image": "dns-master",
            "Volumes": {
                "/etc/bind": {},
                "/var/cache/bind": {},
                "/var/lib/bind": {},
                "/var/log": {}
            },
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.opencontainers.image.ref.name": "ubuntu",
                "org.opencontainers.image.version": "22.04"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "99a608bd8d66608d2cedab1df74a5e54a071fb828f92aa00552b82d45cdc194d",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "53/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "1153"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "1153"
                    }
                ],
                "53/udp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "1153"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "1153"
                    }
                ],
                "953/tcp": [
                    {
                        "HostIp": "127.0.0.1",
                        "HostPort": "953"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/99a608bd8d66",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "labnet": {
                    "IPAMConfig": {
                        "IPv4Address": "192.168.0.2"
                    },
                    "Links": null,
                    "Aliases": [
                        "4e9b9abcf8bc"
                    ],
                    "NetworkID": "049943c94ec4cbd3dd0c5dfcfbe58abfc47f924324653dc3cefd144b432668a6",
                    "EndpointID": "7a3872908cccf95b42e6cbbfd44bd5ff9ddf685fd750d8209bd609060737148e",
                    "Gateway": "192.168.0.1",
                    "IPAddress": "192.168.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:c0:a8:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]