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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support network connect/disconnect to stopped container #18906
Conversation
71e7a76
to
c4c4997
Compare
Awesome, thanks @coolljt0725! |
dockerCmd(c, "network", "connect", "test", "foo") | ||
networks, err := inspectField("foo", "NetworkSettings.Networks") | ||
c.Assert(err, checker.IsNil) | ||
c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' netwokr")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight typo: netwokr -> network
c4c4997
to
366fa37
Compare
@sirlatrom thank you :) |
@@ -610,7 +610,25 @@ func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwo | |||
// ConnectToNetwork connects a container to a network | |||
func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName string) error { | |||
if !container.Running { | |||
return derr.ErrorCodeNotRunning.WithArgs(container.ID) | |||
if container.HostConfig.NetworkMode.IsContainer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of branching with a whole bunch of logic, can we move this to a new function?
I also haven't looked yet, but I'm guessing there is probably some duplicated logic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. we can avoid the code duplication by simply moving the if !container.Running {
check to https://github.com/docker/docker/blob/master/daemon/container_operations_unix.go#L645.
This will avoid the code duplication. But the tricky part will be differentiate the common code-path for connectToNetwork
both from docker run
command and docker network connect
. We may have to check for a better container state than container.Running
because it might be false when called via docker run
& hence might cause issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or (though I don't like this approach) add another bool flag to connectToNetwork
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real issue here is that when the container is not running we are doing something completely different and then returning 100% of the time, there is no shared logic with the code beneath, so for readability it'd be best to move this out to a separate function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. that is also a way to avoid the code-duplication issue & I like it as well.
ping @mrjana |
d74dd44
to
430b24c
Compare
@coolljt0725 not in docs review yet, but there are some minor changes needed in the documentation; https://github.com/docker/docker/blob/master/docs/userguide/networking/work-with-networks.md
https://github.com/docker/docker/blob/master/docs/reference/commandline/network_connect.md
same here; https://github.com/docker/docker/blob/master/man/docker-network-connect.1.md |
@@ -607,10 +607,40 @@ func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwo | |||
return sb | |||
} | |||
|
|||
func (daemon *Daemon) updateNetworks(container *container.Container, idOrName string, updateSettings bool) (libnetwork.Network, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit. The appropriate function name would be updateNetworkConfig
since it does update both the container.Config and also the network specific settings. Can you please change that ?
@coolljt0725 minor comments. Rest of the code and logic LGTM. |
return derr.ErrorCodeNotRunning.WithArgs(container.ID) | ||
} | ||
if container.RemovalInProgress || container.Dead { | ||
return fmt.Errorf("Container is marked for removal and cannot be disconnect to network.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the same "new errcode" referenced in the comment above.
430b24c
to
80dcd11
Compare
early docs review; docs LGTM |
LGTM, nice work! Moving to docs review. |
Ping @jamtur01 @MHBauer @vdemeester 🌴 |
// container but it's marked for removal. | ||
ErrorCodeRemovalContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{ | ||
Value: "REMOVALCONTAINER", | ||
Message: "Container %s is marked for removal and cannot be connected/disconnected to network", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably do:
... connected or disconnected to the network
And same with error msg below too
Docs LGTM - one minor comment. |
@coolljt0725 agree with @jamtur01 comment, once taking care of, LGTM 🐰 |
06b78d0
to
79d4f0f
Compare
Signed-off-by: Lei Jitang <leijitang@huawei.com>
@jamtur01 @vdemeester thanks, updated |
docs LGTM Hum, I don't get why the documentation build has failures… I do not reproduce the failures locally 😓. |
@vdemeester It's weird, I just taken care of the comment of @jamtur01 , no other changes |
hmf, yes, that error is not related, it's an issue with Hugo (probably); see gohugoio/hugo#1754 @SvenDowideit was looking into those, but not sure if he has progress. |
Hmm, looks like GitHub is having issues with their SVN integration on docker/compose?
Manually doing a svn checkout also produces an error (just on the compose repository);
|
Sent an e-mail to GitHub support for the SVN issue |
LGTM - docs failure is not related |
Support network connect/disconnect to stopped container
ping @albers We may need to update bash and zsh completion |
@sdurrheimer Thanks for the ping, created #19293 for bash completion. |
Signed-off-by: Lei Jitang leijitang@huawei.com
see #17796
ping @mavenugo