Internal DNS with Docker CLI

I’m having to launch docker containers via docker’s API to handle backups and I want to be able to reference services via the internal DNS service. For example, I have a mail stack and a service called db. If I run the following docker run command on one of my hosts, I fail to contact the service:

docker run --rm -it -l“true” --dns --dns-search rancher.internal alpine:edge ping -c 3 db.mail

Is there something I’m missing to get the container to use the internal DNS service? I want to use the docker API so the containers clean themselves up when completed since I did not see an equivalent in the Rancher API.

It fails to connect because it takes awhile to set up the internal DNS service.

For example, if you try this:

sudo docker run -d -it -l"true" nginx

If you go into the standalone container, you will be able to ping db.mail

1 Like