bash: line 1: nslookup: command not found in an Ubuntu container means the DNS tools are not installed. Run apt-get update and apt-get install -y dnsutils; that brings nslookup and dig.

If you only need to know whether a name resolves, getent hosts answered in a fresh container before anything was installed.

The error

docker exec fix10-lc-r6 bash -c 'nslookup archive.ubuntu.com 2>&1; echo exit=$?'
bash: line 1: nslookup: command not found
exit=127

The command went through bash -c, which is why the message carries line 1:.

Why it happens

The ubuntu:24.04 image does not contain the package that provides nslookup, so bash finds no program of that name and returns 127. Name resolution itself worked: in a fresh container from the same image, getent, shown below, listed the mirror's addresses before any package was installed.

The name to install is dnsutils. On Ubuntu 24.04 it depends on bind9-dnsutils, and dpkg -S shows the programs come from the latter.

The fix

docker exec fix10-lc-r6 bash -c 'apt-get install -y dnsutils > /dev/null 2>&1; echo install-exit=$?; dpkg -S bin/nslookup bin/dig 2>&1; nslookup archive.ubuntu.com 2>&1 | head -6'
install-exit=0
bind9-dnsutils: /usr/bin/nslookup
bind9-dnsutils: /usr/bin/dig
Server:		192.168.65.7
Address:	192.168.65.7#53

Non-authoritative answer:
Name:	archive.ubuntu.com
...

The Server line shows the resolver the container used; the address on your machine may differ. The output was cut at six lines with head; the name has more addresses.

No install at all, for a quick check, in a fresh container (the first number is the count of installed packages):

docker exec fix10-lc-r9 bash -c 'dpkg -l | grep -c ^ii; getent hosts archive.ubuntu.com; echo exit=$?'
92
...
exit=0

getent printed twelve address lines (cut here) and returned 0. It does not show which server answered, which is what nslookup adds.

The same package also installed dig. For a script, its +short form prints the addresses only, one per line, which is easier to test than the nslookup layout:

docker exec fix10-lc-r6 bash -c 'dig +short archive.ubuntu.com 2>&1; echo exit=$?'
91.189.90.13
91.189.90.12
...
exit=0

Both lists held the same twelve addresses in the test, so either tool tells you the container can resolve names; pick the output format you prefer.

How it was reproduced

The capture was made in a container started with docker run -d --name fix10-lc-r6 ubuntu:24.04 sleep infinity (Ubuntu 24.04.5 LTS, bash 5.2.21) on Docker Engine 29.9.3, with commands sent through docker exec ... bash -c. The installed package was dnsutils 1:9.18.39-0ubuntu0.24.04.9. The lookups went to the public Ubuntu mirror name. The container name is the test's own. Every command was sent from Windows PowerShell 5.1 exactly as shown, with the -c text in single quotes so it reached the container unchanged; a single quote inside that text is written twice, as PowerShell requires.

Frequently asked

Which package provides nslookup on Ubuntu?
Install dnsutils. In the test dpkg -S showed /usr/bin/nslookup and /usr/bin/dig belong to bind9-dnsutils, which dnsutils depends on.
How do I test DNS in a container without nslookup?
Run getent hosts followed by the name. In the test it printed twelve addresses for archive.ubuntu.com and returned 0 in a fresh container before any install.
Why is nslookup not found in my Docker container?
The ubuntu:24.04 image does not include the DNS tools package, so bash finds no nslookup program and returns 127.

More decoded errors in the Fixes category. When the lookup itself fails, see Temporary failure resolving.