fix docker inspect return unconsistent network settings of created container and stopped container#18531
Conversation
|
Will (with this change) |
|
@thaJeztah This change will only affect the
all networks, and nothing to do with this change
no, it will disappear, and also nothing to do with this change
yes, all networks will show, and also nothing to do with this change |
66e914e to
ab6be98
Compare
|
Design review so the nework team can verify |
|
Design LGTM especially we need this in order to support multiple But to clarify one of the questions that @thaJeztah asked
The answer depends on the case. If the container is NOT connected to "bridge" but to another network, then it will show up in the Networks when the container is stopped. I have a few comments on the code though.
|
|
Ok, moving to code review. |
It will stays if the daemon is restarted, because after |
656fa53 to
4ffa298
Compare
|
@mavenugo updated |
There was a problem hiding this comment.
By moving the functionality into UpdateNetworkSettings, this is a case where we must handle properly.
Else, we will end up processing the allocateNetwork for NetworkDisabled || IsContainer() case, which is incorrect.
4ffa298 to
49512c7
Compare
|
@mavenugo Thanks ,updated |
|
@coolljt0725 looks like it fails to build 😢 |
49512c7 to
e514cf4
Compare
|
@thaJeztah Forgot to build on local before pushing to github.... |
daemon/container_operations_unix.go
Outdated
There was a problem hiding this comment.
Does this need to be exported?
There was a problem hiding this comment.
good catch. it should not be exported.
There was a problem hiding this comment.
There is already a method updateNetworkSettings, so I use UpdateNetworkSettings at the very start. what about updateContainerNetworkSettings?
To make docker inspect return a consistent result of networksettings for created container and stopped container, it's bettew to update the network settings on container creating. Signed-off-by: Lei Jitang <[email protected]>
e514cf4 to
c427131
Compare
|
@mavenugo Add a test, is that what you want? |
There was a problem hiding this comment.
This method must be called only the first time and that is the reason why it was originally protected with
if len(container.NetworkSettings.Networks) == 0 {
in the allocateNetwork function.
Without that protection, a container restarted with multiple networks will start to behave incorrectly (especially ungraceful daemon restart cases). I guess we need to add the above protection (``if len(container.NetworkSettings.Networks) == 0 { ) here as well.
There was a problem hiding this comment.
@mavenugo This method does be called only the first time, because create method only be called once. Once the container has been created, the method will never been called again.
There was a problem hiding this comment.
@coolljt0725 you are right :). confused myself with create & start.
|
Thanks @coolljt0725 |
|
Makes sense. Thanks @coolljt0725 |
…g_on_create fix docker inspect return unconsistent network settings of created container and stopped container
There was a problem hiding this comment.
oh, just noticed a typo here; TestDockerNetworkRestartWithMulipleNetworks (muliple -> multiple )
To make docker inspect return a consistent result of networksettings
for created container and stopped container, it's better to update
the network settings on container creating. Or else
docker inspecta createdcontainer will not return the network settings.
as you can see
Networksfiled isnull, it should has the networkbridge, but if start it and then stop it, thendocker inspectwill returnNetworksIt should have the consistent result.
Signed-off-by: Lei Jitang [email protected]