Skip to content

feat(up): use Apple container DNS when domain registered, /etc/hosts fallback otherwise#97

Open
Cyb3rDudu wants to merge 1 commit into
Mcrich23:mainfrom
Cyb3rDudu:feat/dns-domain-resolution
Open

feat(up): use Apple container DNS when domain registered, /etc/hosts fallback otherwise#97
Cyb3rDudu wants to merge 1 commit into
Mcrich23:mainfrom
Cyb3rDudu:feat/dns-domain-resolution

Conversation

@Cyb3rDudu
Copy link
Copy Markdown
Contributor

Closes #81

When a project's sanitized name is already registered via container system dns create, containers are named <svc>.<domain> and get --dns-domain so the daemon's DNS server resolves peers. The /etc/hosts cross-patcher is skipped on this path. When the domain isn't registered, behavior is unchanged — legacy dashed names, /etc/hosts patching, and a one-time note with the sudo command.

ComposeDown tries all candidate name shapes (legacy dashed, dotted DNS, explicit container_name) so teardown works regardless of which mode created the containers.

Changes:

  • sanitizeDnsDomain / dnsListContainsDomain — pure helpers for deriving a DNS label from the project name and checking registration
  • DNS detection in run() — shells out to container system dns list, sets dnsAvailable
  • configService() — passes --name <svc>.<domain> + --dns-domain when DNS is available
  • crossPatchHostsForService — /etc/hosts fallback, gated on !dnsAvailable
  • stopOldStuffByName + ComposeDown multi-shape cleanup

Tested with container 0.12.3 on macOS 26. Two alpine services with name: dnstest — dotted names resolve via getent, /etc/hosts untouched, resolv.conf carries the domain. Auto-skips when no domain is pre-registered.

Static tests: 11 tests covering sanitization rules and dns list parsing.
Dynamic test: end-to-end DNS path verification (skips gracefully without registered domain).

…fallback otherwise

When the project's sanitized name is already registered via
container system dns create, name containers <svc>.<domain> and pass
--dns-domain so the daemon serves DNS for peers. The /etc/hosts
cross-patcher is skipped on this path. Otherwise keep the legacy dashed
names + patcher unchanged, with a notice pointing at the sudo command.

ComposeDown now tries every candidate name shape (legacy, dotted,
explicit) so it cleans up containers from either mode.

Static tests cover sanitizeDnsDomain and dnsListContainsDomain.
Dynamic test verifies dotted naming, peer resolution via getent,
and that /etc/hosts is left untouched when DNS is available.
@Cyb3rDudu Cyb3rDudu force-pushed the feat/dns-domain-resolution branch from 9f2c630 to 1e42796 Compare May 29, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Apple container's built-in DNS for inter-container resolution when domain is registered

1 participant