Skip to main content
DevOps Insightsguides & answers

curl · troubleshooting

curl: (6) Could not resolve host

curl could not turn the host name into an IP address, so it never connected. Either the name is wrong, or DNS is not working from where curl runs, such as inside a container or a CI job.

Reproduced on curl 8.5.0, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 8 sections

Before you start

  • The exact URL, and a shell in the same place curl ran (the container, the runner, the pod).

Run this first

step 1 of 1
getent hosts HOST

Look for An IP address; nothing means resolution fails here too

Resolves the name the way most programs on Linux do, without curl.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

Is the host in the message the one you meant?

Cause space

3 of 3 still possible

  • The host name is wrong or emptyCommon
  • DNS does not work inside the container, runner or podCommon
  • A service name used outside its networkOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    getent hosts HOST

    Resolves the name the way most programs on Linux do, without curl.

    Look for An IP address; nothing means resolution fails here too

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

The host name is wrong or empty

Common

A typo, a missing environment variable that leaves part of the URL empty, or a scheme pasted twice.

Confirm

echo "$URL"

A misspelled, empty or doubled host part

Fix

  • Fix the URL; in scripts, print it before the curl call while debugging.

DNS does not work inside the container, runner or pod

Common

The host machine resolves the name, but the container uses a different resolver, or a private name only resolves inside a VPN or VPC.

Confirm

cat /etc/resolv.conf
getent hosts HOST

No answer from getent, or a nameserver that cannot be reached from here

Fix

  • Use a name that resolves from where the job runs, or configure the container's DNS.
  • Containers on a user-defined Docker network resolve each other by service name; on the default bridge they do not.

A service name used outside its network

Occasional

A Compose service name or Kubernetes Service name only resolves on that network or in that cluster.

Confirm

getent hosts SERVICE

An answer inside the network, none outside it

Fix

  • From outside, use the published port on localhost or the host's address; inside, use the service name.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

Before connecting, curl asks DNS for the address of the host in the URL. Exit code 6 means that lookup failed. Nothing reached the server. Check the name first, then check DNS from the same place curl ran.

Words used on this page

DNS
The system that turns names like api.example.com into IP addresses.
/etc/resolv.conf
Where a Linux system or container lists the DNS servers it asks.
What is actually happening

Reproduced on 23 October 2026 with curl 8.5.0 on Ubuntu 24.04 and curl 8.7.1 on macOS: curl https://build-cache.example.invalid/ printed curl: (6) Could not resolve host: build-cache.example.invalid and exited 6. The .invalid domain is reserved never to resolve, which makes it a safe way to see the error.

The host named in the message is the one curl looked up. If it is not the one you meant, the URL is built wrong; if it is, the problem is DNS from that machine.

How to tell this is your problem
WhereWhat you see
curl, any versioncurl: (6) Could not resolve host: api.example.com

How to know it is actually fixed

  • getent hosts HOST prints an address, and curl gets past the lookup.

Stopping it happening again

  • Fail early in scripts when a variable that builds a URL is empty: ${API_HOST:?}.
  • In CI, resolve the hosts a job needs in a first step, so DNS problems show up as such.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it