Description
When querying a specific port with PortCommand::new(container).port(6379).run(), Docker returns a different output format than when listing all ports, and the parser doesn't handle it.
Expected vs Actual Output
Listing all ports (docker port <container>):
6379/tcp -> 0.0.0.0:40998
6379/tcp -> [::]:40998
Querying specific port (docker port <container> 6379):
Current Behavior
The parser in parse_port_mappings() expects the format <port>/<proto> -> <host>:<port> but when querying a specific port, Docker omits the container port prefix, returning just <host>:<port>.
This causes host_port() in ContainerGuard to fail with:
InvalidConfig("No host port mapping found for container port 6379")
Proposed Fix
Update parse_port_mappings() in src/command/port.rs to handle both formats:
- Full format:
80/tcp -> 0.0.0.0:8080
- Simple format:
0.0.0.0:8080 (when specific port was queried)
For the simple format, the container port can be inferred from the port field in the PortCommand struct.
Affected Code
src/command/port.rs: parse_port_mappings() function
src/testing.rs: host_port() method on ContainerGuard
Discovered While
Adding the examples/testing_utilities.rs example for PR #230.
Description
When querying a specific port with
PortCommand::new(container).port(6379).run(), Docker returns a different output format than when listing all ports, and the parser doesn't handle it.Expected vs Actual Output
Listing all ports (
docker port <container>):Querying specific port (
docker port <container> 6379):Current Behavior
The parser in
parse_port_mappings()expects the format<port>/<proto> -> <host>:<port>but when querying a specific port, Docker omits the container port prefix, returning just<host>:<port>.This causes
host_port()inContainerGuardto fail with:Proposed Fix
Update
parse_port_mappings()insrc/command/port.rsto handle both formats:80/tcp -> 0.0.0.0:80800.0.0.0:8080(when specific port was queried)For the simple format, the container port can be inferred from the
portfield in thePortCommandstruct.Affected Code
src/command/port.rs:parse_port_mappings()functionsrc/testing.rs:host_port()method onContainerGuardDiscovered While
Adding the
examples/testing_utilities.rsexample for PR #230.