nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

fix: Add used port check for publish flag

Open vsiravar opened this issue 1 year ago • 16 comments

Add check for used ports while allocating host port in -p/--publish to make it compatible with docker.

Fixes: https://github.com/containerd/nerdctl/issues/2179

vsiravar avatar Apr 18 '23 00:04 vsiravar

Test failed https://github.com/containerd/nerdctl/actions/runs/4814951537/jobs/8573169644?pr=2190#step:6:982

time="2023-04-27T01:30:38Z" level=fatal msg="failed to load networking flags: bind for :8080 failed: port is already allocated"

junnplus avatar Apr 27 '23 10:04 junnplus

Test failed https://github.com/containerd/nerdctl/actions/runs/4814951537/jobs/8573169644?pr=2190#step:6:982

time="2023-04-27T01:30:38Z" level=fatal msg="failed to load networking flags: bind for :8080 failed: port is already allocated"

This is a test seems is testing TestComposeUpBuild in compose up , not sure if this is related to my change or a flaky test.

vsiravar avatar Apr 28 '23 23:04 vsiravar

Can you test this case locally? It seems different from what was expected?

$ sudo nerdctl run -p 8080:80 --name=test -d nginx
7f4a2be3bd30eba9d9b5c45ea83213af9728fa456bd3b23783a3352282afc078
$ sudo nerdctl stop test
test
$ sudo nerdctl run -p 8080:80 -d nginx
FATA[0000] failed to load networking flags: bind for :8080 failed: port is already allocated

junnplus avatar May 01 '23 01:05 junnplus

Test failed https://github.com/containerd/nerdctl/actions/runs/4814951537/jobs/8573169644?pr=2190#step:6:982

time="2023-04-27T01:30:38Z" level=fatal msg="failed to load networking flags: bind for :8080 failed: port is already allocated"

This is a test seems is testing TestComposeUpBuild in compose up , not sure if this is related to my change or a flaky test.

Not related. It is a flaky test

fahedouch avatar May 01 '23 22:05 fahedouch

@vsiravar Could you confirm this? https://github.com/containerd/nerdctl/pull/2190#issuecomment-1529213083

AkihiroSuda avatar May 18 '23 01:05 AkihiroSuda

@vsiravar Could you confirm this? #2190 (comment)

Sorry I have been a bit busy. I will have all the comments addressed this weekend.

Can you test this case locally? It seems different from what was expected?

$ sudo nerdctl run -p 8080:80 --name=test -d nginx
7f4a2be3bd30eba9d9b5c45ea83213af9728fa456bd3b23783a3352282afc078
$ sudo nerdctl stop test
test
$ sudo nerdctl run -p 8080:80 -d nginx
FATA[0000] failed to load networking flags: bind for :8080 failed: port is already allocated

I think this is because nerdctl stop does not clean up the network unlike nerdctl remove . I can make a follow up PR to fix this, if it's the behavior we want. cc @junnplus

Edit: Tagged Jun for feeback.

vsiravar avatar May 18 '23 18:05 vsiravar

@vsiravar Could you confirm this? #2190 (comment)

Sorry I have been a bit busy. I will have all the comments addressed this weekend.

Can you test this case locally? It seems different from what was expected?

$ sudo nerdctl run -p 8080:80 --name=test -d nginx
7f4a2be3bd30eba9d9b5c45ea83213af9728fa456bd3b23783a3352282afc078
$ sudo nerdctl stop test
test
$ sudo nerdctl run -p 8080:80 -d nginx
FATA[0000] failed to load networking flags: bind for :8080 failed: port is already allocated

I think this is because nerdctl stop does not clean up the network unlike nerdctl remove . I can make a follow up PR to fix this, if it's the behavior we want. cc @junnplus

Edit: Tagged Jun for feeback.

LGTM it is the nerdctl stop responsibility to binded free port(s)

fahedouch avatar Jun 08 '23 17:06 fahedouch

@junnplus LGTY?

AkihiroSuda avatar Jun 12 '23 09:06 AkihiroSuda

I think this is because nerdctl stop does not clean up the network unlike nerdctl remove . I can make a follow up PR to fix this, if it's the behavior we want. cc @junnplus

I apologize for just seeing the new update, thank you for your hard work, I will review it this week.

junnplus avatar Jun 13 '23 04:06 junnplus

LGTM it is the nerdctl stop responsibility to binded free port(s)

I concur with it, but hold reservations about merging this PR. I believe we should first have nerdctl stop manage the release of ports.

The rest LGTM.

junnplus avatar Jun 18 '23 23:06 junnplus

LGTM it is the nerdctl stop responsibility to binded free port(s)

I concur with it, but hold reservations about merging this PR. I believe we should first have nerdctl stop manage the release of ports.

The rest LGTM.

cc vsiravar, could you please fix the stop ( it can be a different PR) so we can merge this accordingly? Thanks

fahedouch avatar Jun 24 '23 12:06 fahedouch

LGTM it is the nerdctl stop responsibility to binded free port(s)

I concur with it, but hold reservations about merging this PR. I believe we should first have nerdctl stop manage the release of ports. The rest LGTM.

cc vsiravar, could please fix the stop ( it can be a different PR) so we can merge this accordingly? Thanks

Sure, I'll work on it in the next couple of weeks.

vsiravar avatar Jun 27 '23 16:06 vsiravar

LGTM it is the nerdctl stop responsibility to binded free port(s)

I concur with it, but hold reservations about merging this PR. I believe we should first have nerdctl stop manage the release of ports. The rest LGTM.

cc vsiravar, could you please fix the stop ( it can be a different PR) so we can merge this accordingly? Thanks

Sure. I will have a PR out this week. Cheers!

vsiravar avatar Jul 05 '23 04:07 vsiravar

What's the current status of this?

AkihiroSuda avatar Aug 07 '23 06:08 AkihiroSuda

What's the current status of this?

I think this PR is good. I am still working on the PR to fix the stop to free binded ports on stop.

vsiravar avatar Aug 08 '23 21:08 vsiravar

@junnplus PTAL

AkihiroSuda avatar Sep 12 '23 06:09 AkihiroSuda