Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(agent/agentcontainers): return host port instead of container port#16866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
johnstcn wants to merge2 commits intomainfromcj/agentcontainers-port-fix

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedMar 10, 2025
edited
Loading

We're currently returning the port mapped inside the container instead of the host port, which is what the agent is able to access.

@johnstcnjohnstcn self-assigned thisMar 10, 2025
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm a bit concerned about the potential disconnect between parsing the docker inspect and deciding where the port should map to. Right now we're discarding half of the information. But one question I have is what happens during the actual port forwarding if, for example, this is our JSON:

docker run -it --rm -p :::8181:8181 -p 127.0.0.1:8181:8182 alpine
"Ports": {"8181/tcp": [          {"HostIp":"::","HostPort":"8181"          }        ],"8182/tcp": [          {"HostIp":"127.0.0.1","HostPort":"8181"          }        ]      }

In this case, host port 8181 is exposed, but it could go to either 8181 or 8182 in the container.

// Parse the containerPortSpec (e.g., "8080/tcp")
parts:=strings.Split(containerPortSpec,"/")

// Get the network protocol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
// Get the network protocol

Nit: Comment why not what. What is inferable from the code.

// Skip if no bindings exist (don't expose the container port)
iflen(bindings)==0 {
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: This check seems like it's not needed, we're iterating on the map keys so technically this can't happen.


// Get the network protocol
network:="tcp"// Default to tcp
iflen(parts)==2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Since this is output fromdocker inspect, we should probably assume len == 2 and anything else is an unexpected state.

Alt: why did we get rid of theconvertDockerPort function when it was more complete?

Port:uint16(hostPort),
})

// Mark this host port as seen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
// Mark this host port as seen


// Process all bindings for this port (usually different interfaces)
for_,binding:=rangebindings {
// Skip if we've already seen this host port
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
// Skip if we've already seen this host port

Port:uint16(hostPort),
})

// Mark this host port as seen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
// Mark this host port as seen

networkPorts:map[string][]dockerPortBinding{
"8080/tcp": {
{HostIP:"0.0.0.0",HostPort:"9090"},
{HostIP:"127.0.0.1",HostPort:"9090"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
{HostIP:"127.0.0.1",HostPort:"9090"},
{HostIP:"127.0.0.1",HostPort:"9090"},
{HostIP:"::",HostPort:"9090"},

For completeness, let's include IPv6

name:"invalid port",
in:"invalid/tcp",
expectError:"invalid port",
name:"no bindings should not create ports",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: Can this actually happen? If not, perhaps we could mention it's only here for completeness?

expectNetwork:"tcp",
name:"no protocol defaults to tcp",
networkPorts:map[string][]dockerPortBinding{
"8080": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: Mentioned earlier, but is this valid output ofdocker inspect?

@johnstcn
Copy link
MemberAuthor

Closing in favour of#16887

@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 12, 2025
@johnstcnjohnstcn deleted the cj/agentcontainers-port-fix branchAugust 29, 2025 16:53
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri left review comments

@SasSwartSasSwartAwaiting requested review from SasSwart

Assignees

@johnstcnjohnstcn

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@johnstcn@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp