Detect port and customize user experience#9
Merged
colindickson merged 3 commits intomasterfrom Nov 17, 2025
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements automatic detection and specialized handling of Docker containers using network ports, with a Docker-specific UX and container actions.
New Features:
Implementation Details:
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.