I've been trying to setup domain name inside a container and check how the embedded Docker DNS deals with those settings.
But I was surprised to see that I was only given a truncated domain name when doing reverse ns lookup.
I set the fqdn to be like ldec<i>.n18.org
The command hostname --fqdn
inside the container returned me ldec1.n18.org
as expected, the ping ping ldec1.n18.org
is working as expected with fqdn properly resolved.
But if I do a reverse ns lookup like dig -x <container_ip>
, I am always returned with a truncated domain name like ldec3.n18
instead of ldec3.n18.org
.
root@ldec3:/# dig -x 172.18.0.4
; <<>> DiG 9.16.37-Debian <<>> -x 172.18.0.4
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21081
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;4.0.18.172.in-addr.arpa. IN PTR
;; ANSWER SECTION:
4.0.18.172.in-addr.arpa. 600 IN PTR ldec3.n18.
;; Query time: 0 msec
;; SERVER: 127.0.0.11#53(127.0.0.11)
;; WHEN: Mon Apr 17 18:59:38 UTC 2023
;; MSG SIZE rcvd: 87
So why dig returns me a truncated domain name ?
To build the image
docker build --tag=debian:11-lde - <<EOF
FROM debian:11
ARG DEBIAN_FRONTEND=noninteractive
ENV APT_CMD="apt-get install -y --no-install-recommends"
# SHELL ["/bin/bash", "-x", "-c"]
RUN echo "===> Add tools..." \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
iputils-ping bind9-dnsutils lsof \
openssh-* \
wget curl \
iptables whois iproute2 net-tools \
vim less sudo bash-completion patch \
ca-certificates \
&& apt-get autoremove -y \
&& echo OK
EOF
To start the 3 containers on the same network
docker network create --driver=bridge n18 --subnet=172.18.0.0/24 || true
for i in $(seq 1 1 3)
do
docker rm -f "ldec${i}" || true
declare domain="n18.org"
docker run --interactive --tty --detach --rm --name "ldec${i}" \
--network=n18 --hostname="ldec${i}.${domain}" \
--dns="8.8.8.8" \
debian:11-lde
done