The inconsistency I am seeing appears to be caused by the preference of juju to select a hostname rather than an IP address if it is configured and to fall back to the lowest IP address if no hostname is configured.
As MAAS configures a DNS hostname for a machine listed in MAAS, but gives out an IP to a container without adding it in to the DNS server as a hostname, so containers only have an IP, no DNS hostname.
Excerpt from network/address.go:
// sortOrder calculates the "weight" of the address when sorting,
// taking into account the preferIPv6 flag:
// - public IPs first;
// - hostnames after that, but "localhost" will be last if present;
// - cloud-local next;
// - machine-local next;
// - link-local next;
// - non-hostnames with unknown scope last.
The inconsistency I am seeing appears to be caused by the preference of juju to select a hostname rather than an IP address if it is configured and to fall back to the lowest IP address if no hostname is configured.
As MAAS configures a DNS hostname for a machine listed in MAAS, but gives out an IP to a container without adding it in to the DNS server as a hostname, so containers only have an IP, no DNS hostname.
Excerpt from network/address.go:
// sortOrder calculates the "weight" of the address when sorting,
// taking into account the preferIPv6 flag:
// - public IPs first;
// - hostnames after that, but "localhost" will be last if present;
// - cloud-local next;
// - machine-local next;
// - link-local next;
// - non-hostnames with unknown scope last.