[lxc-users] Forwarding DNS requests to the host /etc/hosts file

Simos Xenitellis simos.lists at googlemail.com
Wed May 31 13:32:26 UTC 2017


On Wed, May 31, 2017 at 1:46 PM, Adil Baig <simplyadilb at gmail.com> wrote:
> I have several containers running on host machines. The host machine is part
> of a LAN network. Each host has an update /etc/hosts file with domain names
> to other LAN entities.
>
> My problem is I cannot use the hostnames defined on the host inside the
> container (without actually copying the /etc/hosts file in). I'd rather not
> copy the file as I sync /etc/hosts file using Ansible, and the Ansible
> inventory cannot manage LXD containers dynamically.
>
> How is it possible to set up the containers so they look up entries in the
> host machines' /etc/hosts file?
>

As far as I understand, you want to get a container to have access to
the /etc/hosts of its host.
For this to work, the host needs to make a special arrangement in
order to make /etc/hosts
available to the containers.

1. You might be able to do something like

lxc config device add mycontainer etchosts disk path=/etc/hosts
source=/etc/hosts

which means that the container's /etc/hosts is actually the host's /etc/hosts.
The LXD containers have a stock /etc/hosts, therefore on their part
they do not need an individual special entry.

2. Instead of having these static entries (/etc/hosts), you can
consider using a local DNS server.
LXD uses already a separate DNS server (dnsmasq) for the containers,
which by default resolves all those *.lxd hostnames.

Simos


More information about the lxc-users mailing list