Uh oh!
There was an error while loading. Please reload this page.
Fix: Add explicit host entries to container configuration - #1340
Conversation
| var hosts = [ContainerConfiguration.HostEntry(ipAddress: "127.0.0.1", hostnames: ["localhost"])] | ||
| if let primaryAddress { | ||
| let ip = String(primaryAddress.split(separator: "/")[0]) |
There was a problem hiding this comment.
Why are we splitting by / here?
public struct IPv4Address {
@inlinable
public var description: String {
"\(bytes[0]).\(bytes[1]).\(bytes[2]).\(bytes[3])"
}
}
There was a problem hiding this comment.
We are splitting by / here because the value coming in as primaryAddress is not a plain IP address — it is a CIDR notation string (e.g. "192.168.1.45/24").
The /24 part is the subnet mask. We only want the actual IP address (192.168.1.45), so we split on the / and take the first part.
Cleaned-up & safer version of that function:
extension SandboxService {
static func resolvedHosts(
hostname: String,
primaryAddress: String?,
extraHosts: [ContainerConfiguration.HostEntry]
) -> [ContainerConfiguration.HostEntry] {
var hosts: [ContainerConfiguration.HostEntry] = [
ContainerConfiguration.HostEntry(ipAddress: "127.0.0.1", hostnames: ["localhost"])
]
if let primaryAddress {
// Split off the CIDR suffix if present (e.g. "192.168.1.45/24" → "192.168.1.45")
let ipOnly = primaryAddress.split(separator: "/").first.map(String.init) ?? primaryAddress
hosts.append(
ContainerConfiguration.HostEntry(
ipAddress: ipOnly,
hostnames: [hostname]
)
)
}
// Add any extra hosts passed in
hosts.append(contentsOf: extraHosts)
return hosts
}
}
There was a problem hiding this comment.
Why are we splitting by
/here?public struct IPv4Address { @inlinable public var description: String { "\(bytes[0]).\(bytes[1]).\(bytes[2]).\(bytes[3])" } }
Also with the way I am running low latency it must be a steady string no breaking if possible.! I can show you diagrams or math that proves it.
JaewonHur
commented
Apr 14, 2026
It'd be good to have a follow up PR that wires this to CLI (e.g., |
JaewonHur
commented
May 19, 2026
@mazdak Hi! Could you do |
# Conflicts: # Sources/Services/RuntimeLinux/Server/RuntimeService.swift
mazdak
commented
Jun 2, 2026
Apologies for the late reply. Done. |
stephenlclarke
commented
Jun 22, 2026
Thanks for implementing this as a data-shape-only PR. I reviewed the patch from the downstream This looks like the right first slice to me:
I would suggest adding a small Codable compatibility test before merge. This PR is adding a new API field, even though the daemon does not populate it yet, so the important thing to protect is the wire/API shape:
I would also make the meaning of For follow-up work, I would keep the healthcheck pieces split into small PRs:
I do not think those need to be included in this PR. This PR is easier to review if it only adds the shared API field. That gives |
Type of Change
Motivation and Context
While building a Docker Compose-like plugin for container and validating it against our real Docker Compose workload, we hit a core limitation: there was no way for callers to ask the runtime to append explicit entries to a container's /etc/hosts.
That showed up most clearly with Compose extra_hosts, especially the common host.docker.internal pattern. The plugin could parse those mappings, but there was no core field to carry them into the sandbox, so the runtime always generated only the default localhost/container-name entries.
In practice, containers that depended on host aliases still failed name resolution even though the compose file specified them.
Why this belongs in core
This is not something the plugin can fake safely. /etc/hosts is generated in the sandbox layer, so callers need a first-class way to provide additional host entries to the runtime.
What this changes
ContainerConfiguration.HostEntryContainerConfiguration.hostsTesting