Skip to content
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

Merged
merged 1 commit into from Jan 12, 2016

Conversation

coolljt0725
Copy link
Contributor

Signed-off-by: Lei Jitang leijitang@huawei.com

see #17796
ping @mavenugo

@thaJeztah
Copy link
Member

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"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight typo: netwokr -> network

@coolljt0725
Copy link
Contributor Author

@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() {
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

@cpuguy83
Copy link
Member

ping @mrjana

@coolljt0725 coolljt0725 force-pushed the connect_to_created branch 3 times, most recently from d74dd44 to 430b24c Compare December 29, 2015 08:57
@coolljt0725
Copy link
Contributor Author

@cpuguy83 @mavenugo updated

@thaJeztah
Copy link
Member

@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

To connect a container to a network, the container must be running.

https://github.com/docker/docker/blob/master/docs/reference/commandline/network_connect.md

Connects a running container to a network.
(just remove "running")

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) {
Copy link
Contributor

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 ?

@mavenugo
Copy link
Contributor

mavenugo commented Jan 7, 2016

@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.")
Copy link
Member

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.

@thaJeztah
Copy link
Member

early docs review; docs LGTM

@cpuguy83
Copy link
Member

LGTM, nice work!

Moving to docs review.

@icecrime
Copy link
Contributor

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",
Copy link
Contributor

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

@jamtur01
Copy link
Contributor

Docs LGTM - one minor comment.

@vdemeester
Copy link
Member

@coolljt0725 agree with @jamtur01 comment, once taking care of, LGTM 🐰

Signed-off-by: Lei Jitang <leijitang@huawei.com>
@coolljt0725
Copy link
Contributor Author

@jamtur01 @vdemeester thanks, updated

@vdemeester
Copy link
Member

docs LGTM

Hum, I don't get why the documentation build has failures… I do not reproduce the failures locally 😓.

@coolljt0725
Copy link
Contributor Author

@vdemeester It's weird, I just taken care of the comment of @jamtur01 , no other changes

@thaJeztah
Copy link
Member

FATAL: 2016/01/12 mkdir /docs/public/engine/userguide/networking/default_network/images/: no such file or directory

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.

@thaJeztah
Copy link
Member

Hmm, looks like GitHub is having issues with their SVN integration on docker/compose?

Step 3 : RUN svn checkout https://github.com/docker/compose/trunk/docs /docs/content/compose
 ---> Running in b2981df85fd6
svn: E175002: Unexpected HTTP status 500 'Internal Server Error' on '/docker/compose/trunk/docs'

svn: E175002: Additional errors:
svn: E175002: PROPFIND request on '/docker/compose/trunk/docs' failed: 500 Internal Server Error
The command '/bin/sh -c svn checkout https://github.com/docker/compose/trunk/docs /docs/content/compose' returned a non-zero code: 1

Manually doing a svn checkout also produces an error (just on the compose repository);

svn checkout https://github.com/docker/compose/trunk/docs
svn: E175002: Unexpected HTTP status 500 'Internal Server Error' on '/docker/compose/!svn/vcc/default'

svn: E175002: Additional errors:
svn: E175002: REPORT request on '/docker/compose/!svn/vcc/default' failed: 500 Internal Server Error

@thaJeztah
Copy link
Member

Sent an e-mail to GitHub support for the SVN issue

@thaJeztah
Copy link
Member

LGTM - docs failure is not related

thaJeztah added a commit that referenced this pull request Jan 12, 2016
Support network connect/disconnect to stopped container
@thaJeztah thaJeztah merged commit 301627c into moby:master Jan 12, 2016
@sdurrheimer
Copy link
Contributor

ping @albers We may need to update bash and zsh completion

@albers
Copy link
Member

albers commented Jan 13, 2016

@sdurrheimer Thanks for the ping, created #19293 for bash completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet