Member-only story
If you’re using NixOS and encountering the following error when trying to pull images from Docker Hub:
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io: Temporary failure in name resolution
this usually indicates a DNS resolution problem with Docker. Since NixOS uses a declarative configuration, we need to explicitly set the correct DNS resolver to fix the issue.
Cause of the Issue
Docker relies on the system’s DNS configuration to resolve domain names. In some NixOS setups, the /etc/resolv.conf
file may not be correctly configured, leading to DNS resolution failures.
Solution: Configure resolv.conf
in configuration.nix
To fix this issue, we need to ensure that NixOS properly sets the DNS resolver for Docker. Add the following snippet to your configuration.nix
:
{ config, pkgs, ... }:
{
environment.etc = {
"resolv.conf".text = "nameserver 8.8.8.8";
};
}
This configuration explicitly sets the DNS resolver to Google’s 8.8.8.8
, ensuring that DNS queries are correctly resolved.