Network options set in docker run
commands, are not inherited by the CPM runner containers which are spawned separately from the CPM to perform browser and scripted monitor checks. More on this here:
- https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/private-locations/install-containerized-private-minions-cpms#h2-networks
- https://docs.newrelic.com/docs/synthetics/new-relic-synthetics/private-locations/install-containerized-private-minions-cpms#sandboxing-and-docker-deps
Additionally /etc/hosts
will not be automatically copied over to containers by Docker as one would expect for resolv.conf
, so any IP mapping configured there will not be honored, but that being said if you have nameservers to provide to /etc/resolv.conf
should be present.
If your use case requires overriding dns resolution, or manually mapping IPs to hostnames, dnsmasq is handy for this sort of thing. This example is tested on Ubuntu 18.04, here are some instructions to get started:
Install dnsmasq:
apt-get update
apt-get install dnsmasq
Edit /etc/dnsmasq.conf
add the lines:
#have dnsmasq listen to the docker network interface, you can see this interface running `ifconfig`
interface=docker0
#bind our hostname to an address
address=/www.newrelic.com/7.7.7.7
restart dnsmasq
sudo /etc/init.d/dnsmasq restart
By default, dns requests on localhost will pass through dnsmasq, now we also have dns requests that pass through the docker0 interface also use our dnsmasq rules. Since the host loop back interface is not available in a container we can now leverage the docker0 interface.
Get the inet IP of the docker0
running ifconfig
. You may see output like this:
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
To test our configuration run nslookup www.newrelic.com localhost
and nslookup www.newrelic.com 172.17.0.1
(you may need to restart docker for the 2nd one)
Next you’ll want to configure the docker daemon to use the docker0 IP for DNS. This can be done by creating the file /etc/docker/daemon.json
and providing the following json:
{
"dns":["172.17.0.1"]
}
Then restart the docker daemon:
sudo systemctl restart docker
Now start the CPM and give it a test.