Site icon JD Bots

Fixed: failed to lookup address information: Name or service not known (Valkey Admin in Docker)

Featured card titled Fixed: Name or service not known, Valkey Admin in Docker can’t find host.docker.internal, with a warning sign above the labels host.docker.internal and --add-host host-gateway.

Fixed: Name or service not known.

Valkey® Admin, running in Docker, couldn’t connect to the Valkey server on my Mac. It showed this error:

Valkey Admin error

Connection error: Standalone(Received error for address `host.docker.internal:6379`: failed to lookup address information: Name or service not known )

The container couldn’t find the name host.docker.internal. One extra option to docker run fixed it.

What I Was Doing

I was running the web version of Valkey Admin 1.3.0 in Docker Desktop 4.99 on an Apple silicon Mac, with Valkey 9.1 from Homebrew on the same Mac. I started the container like this:

Terminal

docker run -d --name valkey-admin -p 127.0.0.1:8091:8080 valkey/valkey-admin:latest

Then I opened http://localhost:8091, clicked + Add Connection, typed host.docker.internal as the Host, unticked Use TLS and clicked Connect.

What I Expected

Docker’s networking how-tos say a container connects to a service on your computer through the special name host.docker.internal, so I expected the Dashboard to open.

What I Got

The button changed to Connecting…, and then the form showed the error in red:

The connection fails: host.docker.internal can’t be looked up.

What I Checked

Name or service not known means the name couldn’t be looked up at all. So I checked which DNS server the container asks:

Terminal

docker exec valkey-admin cat /etc/resolv.conf

Output

# Generated by Docker Engine.
# This file can be edited; Docker Engine will not make further changes once it
# has been modified.

nameserver 1.1.1.1

# Based on host file: '/etc/resolv.conf' (legacy)
# Overrides: [nameservers]

The container asks 1.1.1.1, a public DNS server. Docker Engine’s settings on this Mac set dns to 1.1.1.1: they live in ~/.docker/daemon.json, which Docker Desktop also shows in its Docker Engine settings.

Docker’s docker run reference says Docker Desktop automatically resolves host.docker.internal, and that --add-host with the special value host-gateway points a name at the internal address of the host.

Why It Happens

Docker Desktop answers the name host.docker.internal itself. With a DNS server set in Docker Engine’s settings, the container asks that server instead, and a public DNS server has never heard of host.docker.internal. Valkey Admin then can’t find the address of your computer.

The Fix

Give the container its own entry for host.docker.internal with --add-host. Remove the container and start it again with the option:

Terminal

docker rm -f valkey-admin

Output

valkey-admin

Terminal

docker run -d --name valkey-admin -p 127.0.0.1:8091:8080 --add-host=host.docker.internal:host-gateway valkey/valkey-admin:latest

Output

2aab0cdc9635b3be6804fd8c8fe76d8ad56cbaff10222c2238c61d6af759101f

Removing the container doesn’t remove the image, so Docker starts the new container without downloading anything. Your Docker DNS setting stays as it is, for the other containers that use it.

After the Fix

I added the same connection again. This time Valkey Admin connected and opened the Dashboard:

Connected: the Dashboard of the local Valkey.

Common Mistakes

MistakeWhat happensDo this instead
Typing localhost as the Host insteadValkey Admin looks for Valkey inside its own containerKeep host.docker.internal and add the option
Changing the Docker DNS setting to fix one containerName lookups change for every containerFix only this container with --add-host

FAQ

Does this happen without Docker Desktop?

Docker’s documentation says Docker Desktop resolves host.docker.internal automatically. Elsewhere, --add-host=host.docker.internal:host-gateway is how you add the name.

Conclusion

Name or service not known means a name couldn’t be resolved. A DNS server set in Docker Engine’s settings hides host.docker.internal from containers, and --add-host=host.docker.internal:host-gateway gives Valkey Admin the name back without changing that setting.

Additional Resources

Related

Valkey® is a registered trademark of LF Projects, LLC. Redis® is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with the Valkey project, LF Projects or Redis Ltd., and isn’t endorsed, supported or certified by them.

Exit mobile version