mirror of
https://github.com/apple/container.git
synced 2026-09-22 23:55:34 +00:00
- Set the container hostname to the first DNS label derived from the container id, strip everything after the first dot. - Fixes #1011.
This commit is contained in:
@@ -849,7 +849,11 @@ public actor SandboxService {
|
||||
czConfig.sockets.append(socketConfig)
|
||||
}
|
||||
|
||||
czConfig.hostname = config.id
|
||||
let containerId = config.id
|
||||
czConfig.hostname =
|
||||
containerId.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true)
|
||||
.first
|
||||
.map { String($0) } ?? containerId
|
||||
|
||||
if let dns = config.dns {
|
||||
czConfig.dns = DNS(
|
||||
|
||||
@@ -97,4 +97,29 @@ class TestCLICreateCommand: CLITest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func testCreateWithFQDNName() throws {
|
||||
let name = "test.example.com"
|
||||
let expectedHostname = "test"
|
||||
#expect(throws: Never.self, "expected container create with FQDN name to succeed") {
|
||||
try doCreate(name: name)
|
||||
try doStart(name: name)
|
||||
defer {
|
||||
try? doStop(name: name)
|
||||
try? doRemove(name: name)
|
||||
}
|
||||
try waitForContainerRunning(name)
|
||||
let inspectResp = try inspectContainer(name)
|
||||
let attachmentHostname = inspectResp.networks.first?.hostname ?? ""
|
||||
let gotHostname =
|
||||
attachmentHostname
|
||||
.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true)
|
||||
.first
|
||||
.map { String($0) } ?? attachmentHostname
|
||||
#expect(
|
||||
gotHostname == expectedHostname,
|
||||
"expected hostname to be extracted as '\(expectedHostname)' from FQDN '\(name)', got '\(gotHostname)' (attachment hostname: '\(attachmentHostname)')"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user