apple / apple/container

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

Open
#402 12 comments 4 reactions 1 assignee Claimed by @jglogan View on GitHub
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### I have done the following

- [x] 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:

```bash
$ 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

```bash
$ ifconfig bridge103
bridge103: flags=8a63 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

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

### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.