Troubleshooting DNS Issues in Docker: Unable to Get Image Due to Lookup Failure

Use this when Docker fails to pull images because name resolution breaks inside the container runtime.

Quick Read

  • Symptom: Use this when Docker fails to pull images because name resolution breaks inside the container runtime.
  • Check first: Verify Docker daemon configuration for DNS settings.
  • Risk: Changes system state

Symptoms

Docker cannot resolve DNS queries, resulting in failure to pull images.

Environment

Docker running on a Linux host, configured to use Google DNS (8.8.8.8).

Most Likely Causes

Misconfiguration in Docker's DNS settings or network issues preventing DNS resolution.

What to Check First

  1. Verify Docker daemon configuration for DNS settings.
  2. Check network connectivity to the DNS server.
  3. Confirm that the Docker service is running.

Fix Steps

  1. Check Docker daemon status.

    Ensure that the Docker service is running properly.

    Safe to run: read-only

    systemctl status docker
  2. Inspect Docker's DNS configuration.

    Check if Docker is configured to use the correct DNS servers.

    Safe to run: read-only

    cat /etc/docker/daemon.json
  3. Test DNS resolution from the host.

    Verify that the host can resolve DNS queries.

    Safe to run: read-only

    nslookup docker
  4. Restart Docker service if DNS settings were modified.

    Apply changes to Docker's configuration by restarting the service.

    Changes system state: review before running

    systemctl restart docker
  5. Check firewall settings.

    Ensure that firewall rules are not blocking DNS traffic.

    Example pattern only. Adjust for your environment before running.

    iptables -L
  6. Test pulling an image after making changes.

    Attempt to pull a Docker image to confirm resolution is working.

    Safe to run: read-only

    docker pull hello-world

Validation

  • Confirm successful image pull.
  • Check Docker logs for any remaining DNS issues.

Logs to Check

  • /var/log/syslog
  • /var/log/docker.log

Rollback and Escalation

  • Revert any changes made to /etc/docker/daemon.json if the issue persists.

Escalate When

  • If DNS issues continue after following all steps.
  • If Docker service fails to restart or behaves unexpectedly.

Edge Cases

  • Check if using a VPN or proxy that might interfere with DNS resolution.
  • Verify if the host's /etc/resolv.conf is correctly configured.

Notes from the Field

  • Ensure that the Docker version is compatible with the host OS.
  • Document any changes made to the Docker configuration for future reference.