Comes late, but you can / could you repeat with:
getent hosts localhost (or getent hosts <dns name> )?
(you will also need to install getent in your getent image along with any runtime dependencies (check ldd getent )
I'm not good at detail, but AFAIU glibc gethostbyname will use NSS as an implementation for name resolution (at least on my OS, RHEL7). Even without nsswitch.conf NSS 'plugins' libnss_files.so and libnss_dns.so represented by default, and therefore these shared objects will be libnss_dns.so dynamically loaded at runtime. If these shared libraries cannot be loaded at runtime (because they are not installed in your clean image), name resolution will fail.
Essentially, you also need to install these shared objects into the image (I also needed libresolv.so , as the dynamically linked libnss_dns.conf dependency). The details of how they probably differ in different OSs, so itβs not easy for me to immediately describe the exact process.
You can track which shared objects are trying to load using strace (using docker run --cap-add SYS_PTRACE <image> strace <command> ).
One final note: not to be confused with the aforementioned problem when dynamically loaded shared objects are missing at runtime. But if you install dynamically linked executables in a container, this blog post describes a way to automatically detect / set link time dependencies (in essence, it uses regular expressions to parse ldd output)
source share