dockerdnsipalpine-linuxnslookup

--add-host does not work as expected. Why?


Here is the command I am running:

docker run --rm --add-host foo:11.12.13.14 alpine nslookup foo

Here is the output I am getting:

Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
9981e73032c8: Pull complete 
Digest: sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454
Status: Downloaded newer image for alpine:latest
Server:     192.168.65.5
Address:    192.168.65.5:53

Non-authoritative answer:

Non-authoritative answer:

While I would expect to see the 11.12.13.14 in the output, since that is the result of the nslookup foo operation after adding the --add-host flag. So, why can not container resolve the foo to its IP address?


Solution

  • Changing the

    docker run --rm --add-host foo:11.12.13.14 alpine nslookup foo

    to the

    docker run --rm --add-host foo:11.12.13.14 alpine:3.8 nslookup foo

    produced the desired result. Hence, the issue in the newer versions of the alpine.