bbarker
1
I’m trying to write a declarative container and am having issues with host name resolution:
Setting this in my container’s config entry did not help:
networking.useHostResolvConf = true;
My resolv.conf does not contain any nameserver.
Is there a way to fix this, particularly in a declarative fashion?
bbarker
2
It looks like something is going on here though I’m not quite sure what, since it has --remove-destination
.
In any case, my host and container resolv.conf files definitely do not match.
bbarker
3
I was able to fix this using hte bindMounts
container option, like:
containers.flx_web =
{ autoStart = true;
privateNetwork = true;
hostAddress = "192.168.100.10";
localAddress = "192.168.100.11";
bindMounts = {
"/etc/resolv.conf" = {
hostPath = "/etc/resolv.conf";
isReadOnly = true;
};
};
blitz
4
This is still an issue with 20.03. Maybe the container is created before networking is up in the host and there is no resolv.conf to copy?
blitz
5
Yes, I think the problem is this part of the systemd config:
if containerConfig.autoStart then
{
wantedBy = [ "machines.target" ];
wants = [ "network.target" ];
after = [ "network.target" ];
restartTriggers = [
in https://github.com/NixOS/nixpkgs/blob/0023908b4ecef4e889a9bb524394f53c014950fe/nixos/modules/virtualisation/nixos-containers.nix. When the host uses DHCP, this means that the container is started before the host knows its DNS server. The wants/targets sections should be network-online.target
instead.