Skip to content

Comments

Detect port and customize user experience#9

Merged
colindickson merged 3 commits intomasterfrom
claude/port-detection-experience-017FkgfG3qSzqBVTm6SvbDkw
Nov 17, 2025
Merged

Detect port and customize user experience#9
colindickson merged 3 commits intomasterfrom
claude/port-detection-experience-017FkgfG3qSzqBVTm6SvbDkw

Conversation

@colindickson
Copy link
Member

Implements automatic detection and specialized handling of Docker containers using network ports, with a Docker-specific UX and container actions.

New Features:

  • Automatic Docker container detection via multiple strategies:
    • docker-proxy process detection with container IP extraction
    • cgroup path analysis for containerized processes
    • environment variable inspection for Docker indicators
  • Docker-specific display mode with container details:
    • Container identity (name, ID, state, uptime)
    • Image information (name, ID, platform, command)
    • Network configuration (ports, IP, gateway, networks)
    • Resource usage (CPU, memory, network I/O, block I/O, PIDs)
    • Container configuration (restart policy, mounts, labels)
  • Docker container actions (instead of killing processes):
    • Stop container (docker stop)
    • Stop and remove container (docker stop + docker rm)
    • Force remove running container (docker rm -f)
    • Interactive prompt with cancellation option

Implementation Details:

  • internal/docker/detector.go: Multi-strategy Docker detection
  • internal/docker/retriever.go: Container info via docker inspect/stats
  • internal/docker/container.go: ContainerInfo data model
  • internal/docker/action.go: Container action handler with prompting
  • internal/display/docker/displayer.go: Docker-specific UI formatter
  • cmd/whoseport/main.go: Integration with main flow and routing

The implementation follows the existing SOLID architecture with interface-driven design, graceful fallback when Docker is unavailable, and comprehensive test coverage. The Docker-specific UI maintains the same colorful, emoji-enhanced style as the process UI while clearly distinguishing container-related information.

Documentation updated in README.md and CLAUDE.md to describe Docker support, detection strategies, display format, and action options.

Implements automatic detection and specialized handling of Docker containers
using network ports, with a Docker-specific UX and container actions.

New Features:
- Automatic Docker container detection via multiple strategies:
  * docker-proxy process detection with container IP extraction
  * cgroup path analysis for containerized processes
  * environment variable inspection for Docker indicators
- Docker-specific display mode with container details:
  * Container identity (name, ID, state, uptime)
  * Image information (name, ID, platform, command)
  * Network configuration (ports, IP, gateway, networks)
  * Resource usage (CPU, memory, network I/O, block I/O, PIDs)
  * Container configuration (restart policy, mounts, labels)
- Docker container actions (instead of killing processes):
  * Stop container (docker stop)
  * Stop and remove container (docker stop + docker rm)
  * Force remove running container (docker rm -f)
  * Interactive prompt with cancellation option

Implementation Details:
- internal/docker/detector.go: Multi-strategy Docker detection
- internal/docker/retriever.go: Container info via docker inspect/stats
- internal/docker/container.go: ContainerInfo data model
- internal/docker/action.go: Container action handler with prompting
- internal/display/docker/displayer.go: Docker-specific UI formatter
- cmd/whoseport/main.go: Integration with main flow and routing

The implementation follows the existing SOLID architecture with interface-driven
design, graceful fallback when Docker is unavailable, and comprehensive test
coverage. The Docker-specific UI maintains the same colorful, emoji-enhanced
style as the process UI while clearly distinguishing container-related
information.

Documentation updated in README.md and CLAUDE.md to describe Docker support,
detection strategies, display format, and action options.
The previous Docker detection logic only worked on Linux because it relied
on Linux-specific features like /proc filesystem and docker-proxy processes.
On macOS with Docker Desktop, the port forwarding is handled by
com.docker.backend, which wasn't being detected properly.

Changes:
- Updated Detector interface to accept port parameter for port-based lookup
- Added new detection strategy that queries Docker directly for containers
  with matching port mappings using 'docker ps --format json'
- Made this the primary strategy (Strategy 1) as it works on both Linux and macOS
- Added containerHasPort helper to parse Docker's port mapping format
- Handles various port formats: 0.0.0.0:8080, :::8080, *:8080, etc.
- Updated main.go to pass port to detector.IsDockerRelated()
- Added comprehensive tests for port matching logic

This fix enables Docker container detection on macOS Docker Desktop by
checking if the process name contains "docker" (like com.docker.backend
or docker-proxy) and then querying Docker for containers that have port
mappings matching the searched port.

The detection now works across platforms:
- Linux: Uses docker-proxy detection, cgroup analysis, or port-based lookup
- macOS: Uses port-based lookup when com.docker.backend is detected
- Both: Gracefully falls back to regular process display if Docker unavailable

Fixes the issue where whoseport would show the Docker backend process
instead of the actual container information on macOS.
@colindickson colindickson merged commit d1415ad into master Nov 17, 2025
8 of 9 checks passed
@colindickson colindickson deleted the claude/port-detection-experience-017FkgfG3qSzqBVTm6SvbDkw branch November 17, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants