Skip to content

Conversation

shin-
Copy link
Contributor

@shin- shin- commented Jul 29, 2015

Follow-up to #691 - Tested with docker/docker master.

@aanand @jhowardmsft - please review!

@lowenna
Copy link
Contributor

lowenna commented Jul 29, 2015

Oh that's much better! LGTM (but not verified against docker and my docker change yet).

@shin-
Copy link
Contributor Author

shin- commented Jul 29, 2015

Do you mind giving it a whirl against your branch when you have some time? Thanks!

@lowenna
Copy link
Contributor

lowenna commented Jul 29, 2015

Absolutely. Will try and get to it this evening.

@lowenna
Copy link
Contributor

lowenna commented Jul 30, 2015

@shin- Verified against my branch for PR 14530 in docker. LGTM 👍 Thanks for following through :)

@aanand
Copy link
Contributor

aanand commented Jul 30, 2015

What's the purpose of all the network_mode='none' stuff in the tests?

@lowenna
Copy link
Contributor

lowenna commented Aug 3, 2015

Hi @aanand - The reason relates to moby/moby#14530 and mentioned in #691. The daemon with 14530 will do network mode validation - previously it was done by the CLI. This is necessary as part of the port of the daemon to Windows where network modes are different between Linux and Windows. Hence, a more complete host config is necessary to be passed to the daemon. Strictly speaking, it probably should have been there before as many of the tests aren't passing a "complete" host config structure, but instead are passing the minimal set to allow the docker-py tests to pass. Hope that makes sense :)

docker/client.py Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shin- can correct me, I'm not a python person at all. I believe its just a shortcut to ensure that network_mode is always present when calling create_host_config. Therefore you don't need to have the code I originally had to add to the dictionary if it isn't present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a compelling reason not to do it in create_host_config?

It looks like the fallback check there is for network_mode is None. This will be false if network_mode is the empty string. So it seems like the behaviour of start and create_host_config will differ when the network_mode kwarg is omitted:

  • client.start(container) will start a container with a network_mode of default.
  • create_host_config() will return a host config object without a NetworkMode key.

If NetworkMode is now required in host config objects, I feel create_host_config should always set it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's so that if the user doesn't provide an explicit value, we avoid creating a non-empty config in start (see https://github.com/docker/docker-py/blob/jhowardmsft-14530-netmode/docker/utils/utils.py#L431 - not passing None will prevent this field from being populated). It's kind of a hack, but the problem is that if a host_config is provided in start it will override the one provided in create_container, so we need to prevent that from happening (see 09a5eb8)

There's an argument for removing config from start entirely but I don't know if we're quite there yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, that makes sense. (I'd be in favour of removing start's arguments soon.)

Could we make it clearer what's happening? Perhaps:

start_config_kwargs = dict(
    binds=binds, port_bindings=port_bindings, lxc_conf=lxc_conf,
    publish_all_ports=publish_all_ports, links=links, dns=dns,
    privileged=privileged, dns_search=dns_search, cap_add=cap_add,
    cap_drop=cap_drop, volumes_from=volumes_from, devices=devices,
    network_mode=network_mode, restart_policy=restart_policy,
    extra_hosts=extra_hosts, read_only=read_only, pid_mode=pid_mode,
    ipc_mode=ipc_mode, security_opt=security_opt, ulimits=ulimits
)

start_config = None

if any(v is not None for v in start_config_kwargs.values()):
    start_config = create_host_config(**start_config_kwargs)

@shin- shin- mentioned this pull request Aug 6, 2015
@shin- shin- added this to the 1.4.0 milestone Aug 10, 2015
shin- added a commit that referenced this pull request Aug 10, 2015
`network_mode` now necessary in `host_config`
@shin- shin- merged commit 139850f into master Aug 10, 2015
@shin-
Copy link
Contributor Author

shin- commented Aug 10, 2015

Merged, sorry for the delay!

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

Successfully merging this pull request may close these issues.

3 participants