diff --git a/Sources/Container-Compose/Commands/ComposeUp.swift b/Sources/Container-Compose/Commands/ComposeUp.swift index 126d637..aa23987 100644 --- a/Sources/Container-Compose/Commands/ComposeUp.swift +++ b/Sources/Container-Compose/Commands/ComposeUp.swift @@ -598,16 +598,27 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable { return imageToRun } + // Resolve context path (handle absolute paths and tilde expansion) + let contextPath: String + if buildConfig.context.hasPrefix("/") { + contextPath = buildConfig.context + } else if buildConfig.context.hasPrefix("~") { + contextPath = NSString(string: buildConfig.context).expandingTildeInPath + } else { + contextPath = "\(self.cwd)/\(buildConfig.context)" + } + // Build command arguments - var commands = ["\(self.cwd)/\(buildConfig.context)"] - + var commands = [contextPath] + // Add build arguments for (key, value) in buildConfig.args ?? [:] { commands.append(contentsOf: ["--build-arg", "\(key)=\(resolveVariable(value, with: environmentVariables))"]) } - - // Add Dockerfile path - commands.append(contentsOf: ["--file", "\(self.cwd)/\(buildConfig.dockerfile ?? "Dockerfile")"]) + + // Add Dockerfile path - should be relative to context, NOT cwd + let dockerfilePath = "\(contextPath)/\(buildConfig.dockerfile ?? "Dockerfile")" + commands.append(contentsOf: ["--file", dockerfilePath]) // Add caching options if noCache {