Reputation: 16315
When I ping a URL from my Ubuntu system it resolves correctly to the IP of the desired server. When I do the same thing from within my container it resolves to some other IP (I think its an old DNS entry).
Does anyone know why this happens and how to fix it?
I run the container with the following command:
docker run -it -v $(pwd):/data-storage dotnet-testbed /bin/bash
Pinging Google works:
PING google.com (172.217.19.174): 56 data bytes
64 bytes from 172.217.19.174: icmp_seq=0 ttl=54 time=4.537 ms
pinging the myUrl shows the wrong ip and gets stuck:
PING myUrl (**.***.***.**): 56 data bytes
Upvotes: 0
Views: 3022
Reputation: 8056
You may find the following techniques useful to investigate how your Docker container resolves a hostβ¦
Search the hosts database:
π docker run alpine getent hosts stackoverflow.com
151.101.1.69 stackoverflow.com stackoverflow.com
Check the hosts file:
π docker run alpine cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3 6a431f90415d
Check the hosts added to the container's hosts file explicitly by docker run --add-host
:
π docker run --name=my_cool_container -i -d --add-host stackoverflow.com:127.0.0.1 alpine sh
π docker inspect -f '{{range $index, $value := .HostConfig.ExtraHosts}}{{$value}}
{{end}}' my_cool_container
stackoverflow.com:127.0.0.1
But maybe this doesn't have so much to do with Docker. You should run ifconfig
inside the container and check whether its DNS server is the same as your host machine's. You can also use dig
to check the DNS answer that it receives.
I'd be very surprised if this was an "old DNS entry" in the container (containers are often short-lived). If so: you could fix that by redeploying the container (or learning how to purge its DNS cache).
Most likely: there's some proxy that your host machine uses, but the container does not. By default, Docker containers use bridge networking. If you switch it to use host networking: the container will use your host's networking stack. This may be enough to make it benefit from your proxy.
Upvotes: 1
Reputation: 495
Are you behind a proxy?... You can set http_proxy as environment variable in your container .. or pass as an argument for building purpouses
Upvotes: 0