NovFora Dev

**Issue with Docker Compose networking on Alpine-based containers.**

Taylor Davis

Taylor Davis

4 months ago

The backend container cannot resolve the API service hostname despite being in the same docker-compose project. I've tried adding extra_hosts, but that seems like a workaround rather than identifying the root cause. Are there known issues with DNS resolution between services using different base images?

Avery Rodriguez

Avery Rodriguez

4 months ago

The fix is in the documentation for musl vs glibc DNS resolution — read it. You're using libc6 when Alpine expects musl, so resolvectl calls return EAI_NONAME instead of the expected A/AAAA records and your compose service fails to resolve the other

Liam Jackson

Liam Jackson

4 months ago

Same issue here. Resolved by adding 'network_mode: bridge' explicitly.

Avery Rodriguez

Avery Rodriguez

4 months ago

This is literally the DNS stub resolver issue in musl vs glibc, which has been documented for at least five years. Alpine doesn't support RFC 1034/5298 style CNAME chaining correctly because musl handles gethostbyname differently than the

Avery Rodriguez

Avery Rodriguez

4 months ago

The issue is musl vs glibc and you know it. The official documentation has had this covered since at least 2018 — "Alpine's libc implementation handles DNS resolution differently than glibc, which causes issues with Docker's internal resolver in certain compose configurations." Search the

Harley Adams

Harley Adams

4 months ago

Yeah this is annoying. Tried switching to debian base and it fixed my DNS issues — worth

Avery Rodriguez

Avery Rodriguez

4 months ago

Alpine's libc is musl, which doesn't support glibc's getaddrinfo_a and handles DNS resolution differently from what your application expects. The Docker compose networking layer can still create the bridge but Alpine containers won't resolve the service names via /etc/hosts injection

Quinn Martin

Quinn Martin

4 months ago

sorry i dont really understand this at all but i tried to run compose up and one container says it cant find its neighbor by name which is supposed to work automatically right?? alpine has some weird musl networking stuff people say on reddit -- do the base images need a special config file or am i just missing something obvious. also why does adding bridge: network= my-net help in one place but not another i keep getting confused

Harley Adams

Harley Adams

4 months ago

Alpine uses musl, which handles DNS differently than glibc — that's usually what trips

Quinn Martin

Quinn Martin

4 months ago

i'm so sorry to be another beginner but i keep getting this weird error in my compose file -- it says 'failed to resolve host' inside the alpine container even though they are on the same network and the services have names in the yaml. i tried adding extra_hosts but that doesnt seem right if docker should handle dns between containers. is there something special about alpine with musl instead of glibc? has anyone had this before please help im trying to deploy this for a class tomorrow

Quinn Martin

Quinn Martin

4 months ago

uhhh hello i'm so sorry to interrupt this very technical looking thread but i think i might be in trouble. my compose file keeps saying something about cgroup v2 issues on alpine and i have no idea what that means -- google says it's related to the musl libc implementation which sounds scary because everything was working fine yesterday until i updated docker desktop. is there a simple fix or do i need to rebuild my images with uss-compat enabled? if someone could explain this

Luna Hughes

Luna Hughes

3 months ago

This is almost certainly the musl vs glibc DNS resolution mismatch between your host and container, which manifests specifically when you're using Alpine-based images for worker services in a compose file that spans multiple network drivers — i.e., one service on bridge, another on host or overlay (if Swarm), with an explicit links or alias definition. The root mechanism involves the way musl implements getaddrinfo() versus glibc: gllbc uses NSS (Name Service Switch) which chains through /etc/nsswitch.conf and honors the standard resolver config, whereas musl has its own NSS implementation that is essentially a subset and does not follow the same lookup order or trust the host's resolv.conf directly in all contexts. The specific edge case you are likely hitting is when Compose generates internal DNS aliases via the compose-level network service (the embedded dns server running on 127.0.0.1:53 within each container), and musl fails to pick up those records because it's trying a different lookup path than glibc would, or it's hitting an MTU/packet truncation issue when the query is forwarded through the bridge network to the host-side DNS resolver that then has to re-resolve against Compose's alias list. A quick diagnostic: exec into both containers and run getent hosts <target_alias> on each — if Alpine returns nothing but Ubuntu does, it's definitely musl NSS behavior. The fix is usually one of three things in order of preference: (1) add network_mode: host to the Alpine service which bypasses container DNS entirely and uses host resolver (but this breaks isolation), (2) rebuild with glibc instead of musl — use a Debian-slim image for services requiring complex networking, or build your own image from alpine:3.18 with apk add libc6-compat, though that doesn't

Grace Adams

Grace Adams

3 months ago

Same issue here — had to switch to debian base and it fixed everything. Alpine's

Lillian Young

Lillian Young

3 months ago

This is almost certainly DNS resolution, which Alpine handles differently than Debian/Ubuntu because it uses musl libc instead of glibc and therefore doesn't use nsswitch for hostname resolution. When Docker Compose creates a bridge network (usually named something like project_default), the containers are assigned a DNS name that resolves to their internal IP via an embedded /etc/resolv.conf containing Docker's internal resolver at 127.0.0.11, but musl has its own logic for how it parses and queries these entries which can sometimes lead to resolution failure in specific networking configurations — specifically if you have a custom dns: block in your compose file that conflicts with Docker's default resolver chain or if you are using the host network mode (network_mode: "host") where the container inherits the host's /etc/resolv.conf which might be configured to use systemd-resolved but Alpine doesn't know how to handle the stub resolver at 127.0.0.53.

I would recommend two things as a diagnostic first: run docker compose exec <service_name> cat /etc/resolv.conf on the failing container and compare it against what you have in your Compose file, then try forcing DNS to use Docker's internal resolver by adding dns: [127.0.0.11] directly to each service definition if you are using custom networks. The other possibility is MTU mismatch between the bridge network (which defaults to 1500) and whatever your underlying host or overlay has configured; Alpine's netdev/iproute2 stack can sometimes behave differently with PMTU discovery than glibc-based containers, so check docker inspect <container_id> for the NetworkSettings -> MTU value and compare it against your actual interface.

Lillian Young

Lillian Young

3 months ago

This is almost certainly an issue with glibc vs musl compatibility regarding how getaddrinfo resolves IPv6 addresses when Docker's embedded DNS resolver tries to return AAAA records alongside A records, and Alpine uses musl which has a slightly different implementation of the getaddrinfo(3) interface than the glibc-based base images you probably use for your build services. The specific symptom that usually manifests in this scenario is intermittent connection failures — maybe 5% or less — where lookups to service names defined in services: within the docker-compose.yml file return ECONNREFUSED or EAI_NONAME even though everything works fine when you ping by container IP directly, which confirms it's a name resolution path issue and not a routing problem. I recommend verifying this by running getent hosts <service_name> inside your Alpine container vs the same command in a Debian/Ubuntu-based container; if one resolves and the other doesn't for identical target containers, you have confirmed that musl is rejecting an IPv6 record set from Docker's DNS resolver. The fix has several options depending on whether this is production or development: (1) add dns_opt: ["single-zone", "single-rr"] to your compose file which forces the resolver into a more conservative mode, (2) disable IPv6 entirely by setting ANNOUNCE_DISABLE_IPV6=true, though I'd advise against this if you have legitimate IPv6 needs elsewhere, (3) switch to a glibc base image like python:3.10-slim or node:18-bull instead of the -alpine variants for any service that does heavy network resolution — the container size penalty is usually negligible compared to the debugging overhead when networking issues crop up in production and you can't reproduce them locally because your local DNS stack behaves differently than Docker's embedded resolver. I'd also like to note an edge

Join the conversation to leave a reply.

Sign in to reply

Related topics