Skip to content

Commit 6127b02

Browse files
committed
Handle compose down with container_name case
1 parent 2c24fef commit 6127b02

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Sources/Container-Compose/Commands/ComposeDown.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,37 @@ public struct ComposeDown: AsyncParsableCommand {
103103
})
104104
}
105105

106-
try await stopOldStuff(services.map({ $0.serviceName }), remove: false)
106+
try await stopOldStuff(services, remove: false)
107107
}
108108

109-
private func stopOldStuff(_ services: [String], remove: Bool) async throws {
109+
private func stopOldStuff(_ services: [(serviceName: String, service: Service)], remove: Bool) async throws {
110110
guard let projectName else { return }
111-
let containers = services.map { "\(projectName)-\($0)" }
112111

113-
for container in containers {
114-
print("Stopping container: \(container)")
115-
guard let container = try? await ClientContainer.get(id: container) else { continue }
112+
for (serviceName, service) in services {
113+
// Respect explicit container_name, otherwise use default pattern
114+
let containerName: String
115+
if let explicitContainerName = service.container_name {
116+
containerName = explicitContainerName
117+
} else {
118+
containerName = "\(projectName)-\(serviceName)"
119+
}
120+
121+
print("Stopping container: \(containerName)")
122+
guard let container = try? await ClientContainer.get(id: containerName) else {
123+
print("Warning: Container '\(containerName)' not found, skipping.")
124+
continue
125+
}
116126

117127
do {
118128
try await container.stop()
129+
print("Successfully stopped container: \(containerName)")
119130
} catch {
120131
print("Error Stopping Container: \(error)")
121132
}
122133
if remove {
123134
do {
124135
try await container.delete()
136+
print("Successfully removed container: \(containerName)")
125137
} catch {
126138
print("Error Removing Container: \(error)")
127139
}

0 commit comments

Comments
 (0)