Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/tty/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package tty
import (
"os"
"strings"

"github.com/githubnext/gh-aw-mcpg/internal/logger"
)

var log = logger.New("tty:container")

// IsRunningInContainer detects if the current process is running inside a container
func IsRunningInContainer() bool {
log.Print("Detecting container environment")

// Method 1: Check for /.dockerenv file (Docker-specific)
if _, err := os.Stat("/.dockerenv"); err == nil {
log.Print("Container detected: /.dockerenv file exists")
return true
}

Expand All @@ -20,14 +27,17 @@ func IsRunningInContainer() bool {
strings.Contains(content, "containerd") ||
strings.Contains(content, "kubepods") ||
strings.Contains(content, "lxc") {
log.Printf("Container detected: found container indicator in /proc/1/cgroup")
return true
}
}

// Method 3: Check environment variable (set by Dockerfile)
if os.Getenv("RUNNING_IN_CONTAINER") == "true" {
log.Print("Container detected: RUNNING_IN_CONTAINER=true")
return true
}

log.Print("No container environment detected")
return false
}