[Lxc-users] Container name as DNS name

Ben Butler-Cole ben at bridesmere.com
Fri Aug 24 16:52:07 UTC 2012


On 6 July 2012 19:56, Serge Hallyn <serge.hallyn at canonical.com> wrote:
> Quoting Ben Butler-Cole (ben at bridesmere.com):
>> For some reason I thought that with the default lxcbr0 config the
>> containers name would resolve for it as a DNS name. That doesn't seem to be
>> the case.
>
> Do you have 10.0.3.1 (or whatever ip address you have assigned to lxcbr0)
> added as a nameserver, i.e. in /etc/resolv.conf?

I don't have 10.0.3.1 in /etc/resolv.conf. That would be good enough,
and I have put it there by various hacky approches. But I'm not sure,
with resolvconf controlling /etc/resolv.conf, what the correct way of
doing this is. Do you have any idea what a sensible way to do it would
be?

I have a work-around that works well enough (which is why I went quiet
on this thread). My main reason for reviving the thread is to post the
workaround in case it helps someone else.

You can use dig, specifying the local nameserver, to get hold of the
IP address. So SSHing to the container looks like this:

  ssh $(dig @10.0.3.1 ${CONTAINER_NAME})

There are a couple of wrinkles. You have to wait for the container to
request an IP address from dnsmasq before you can resolve the IP
address (in practice I poll for a result after staring the container
in order that later calls are guaranteed to work). And you can get
stale results from dig if you destroy a container and then start one
with the same name (I tried sending dnsmasq a SIGHUP, but this doesn't
appear to clear the cache sufficiently; in practice I work around this
by appending a UID to all container names).

-Ben




More information about the lxc-users mailing list