curl: (6) Could not resolve host: wbe means curl could not turn the host name in
the URL into an address, so it never tried to connect. Check the name first, then check
whether the machine can resolve any name at all; getent hosts answers both
questions.
If getent hosts finds a name you know exists but not the one in your URL, the URL
has a typo or names a host that is not there. If it finds nothing at all, the problem is name
resolution on the machine, and correcting the URL will not help.
The error
$ curl -sS http://wbe:8080/
curl: (6) Could not resolve host: wbe
exit=6
Why it happens
Before curl opens a connection it asks the system for the address of the host in the URL.
Here the server container is called web on a Docker network, and the URL said
wbe. No address came back, curl stopped and exited with code 6. The same exit
code and the same wording came back in a second container started with
--network none, where the URL was spelled correctly but the container had only a
loopback interface and no way to reach a DNS server. The message alone does not tell the two
cases apart.
$ curl -sS http://archive.ubuntu.com/
curl: (6) Could not resolve host: archive.ubuntu.com
exit=6
The fix
Ask the resolver directly. In the container on the Docker network, the typo returned nothing (exit code 2), while the server's real alias and a public name both resolved:
$ getent hosts wbe
exit=2
$ getent hosts web
172.20.0.4 web
exit=0
$ curl -sS -o /dev/null -w '%{http_code}\n' http://web:8080/
200
exit=0
$ getent hosts archive.ubuntu.com
...
exit=0
So the fix there was the URL: web instead of wbe, and curl got a
200. In the --network none container, getent hosts archive.ubuntu.com
also returned nothing with exit code 2, which points at the machine, not the URL. For that
container the answer was a network, not a different URL. After
docker network disconnect none fix10-ln-none and
docker network connect fix10-ln-net fix10-ln-none (the test's own names), the
same URL returned 200:
$ curl -sS -o /dev/null -w '%{http_code}\n' http://archive.ubuntu.com/
200
exit=0
Between containers, the name that resolved here was the network alias web, given with
docker network connect --alias web on the network both containers shared.
How it was reproduced
Reproduced inside ubuntu:24.04 containers on Docker engine 29.9.3, with
curl 8.5.0 installed by apt-get install -y curl. A Python 3.12.3
http.server on port 8080 ran in a second container with the network alias
web on a user-defined Docker network; the client container sat on the same
network. The --network none case used a third container from
fix10-ln-tools, an image committed from the client container so that it had
curl without a network.
The containers and the network were removed afterwards.
Frequently asked
- What does curl: (6) Could not resolve host mean?
- curl could not get an address for the host name in the URL, so it never connected. Either the name is wrong or the machine cannot resolve names at all.
- How do I tell a typo from a DNS problem with curl error 6?
- Run getent hosts on the name from the URL and on a name you know exists. If only your name fails, fix the URL. If both fail, the machine has no working name resolution.
- Why does curl say Could not resolve host inside a Docker container?
- In this test it happened when the URL had a typo in the container name, and when the container was started with --network none. With both containers on one user-defined network, the alias of the server container resolved.
If the name resolves but the connection is refused, that is a different error: curl: (7) Failed to connect to localhost port 8080. More decoded errors in the Fixes category.