Skip to content

[Bug]: DNS Resolution Fails in Containers When a Local Service Binds to Port 53 on Specific Interfaces #402

@samurai00

Description

@samurai00

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

  1. On the macOS host, configure and run a local DNS service like dnsmasq.
  2. Crucially, configure this service to listen on port 53, but only on specific interfaces (e.g., lo0 at 127.0.0.1:53 and en0 at 192.168.24.39:53). It should not be listening on all interfaces (*:53).
  3. Start the apple/container environment.
  4. Attempt to resolve an external domain from within a container.
  5. Alternatively, try to build an image that requires network access during the build process.

Current behavior

DNS resolution inside the container fails. The container's default DNS server, 192.168.64.1, is unreachable.

For instance, running nslookup inside a container results in a connection timeout:

$ container run --rm -i -t alpine:latest nslookup www.apple.com
nslookup: read: Connection refused
nslookup: read: Connection refused
;; connection timed out; no servers could be reached

Additional Context

$ ifconfig bridge103
bridge103: flags=8a63<UP,BROADCAST,SMART,RUNNING,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.64.1 netmask 0xffffff00 broadcast 192.168.64.255
        ...
  • The Conflict: The root cause is a port binding conflict. My dnsmasq service listens only on specific interfaces (e.g., 127.0.0.1:53).
  • The Proof: The issue is resolved 100% of the time by stopping my dnsmasq service. When it's off, apple/container successfully uses the host's mDNSResponder to bind *:53 and provide working DNS to containers.
  • The Hypothesis: The container's DNS proxy (via mDNSResponder) attempts a global bind to *:53. This fails if port 53 is already in use on any interface, preventing the DNS service for the container network gateway (192.168.64.1) from starting.

Expected behavior

  • DNS resolution inside the container should work correctly using the default 192.168.64.1 resolver.
  • The presence of another service on the host listening on 127.0.0.1:53 or 192.168.24.39:53 should not interfere with the container's DNS functionality.

Environment

- OS: macOS 15.6
- Xcode: Version 16.4 (16F6)
- Container: container CLI version 0.3.0 (build: release, commit: 3fcf647)

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions