question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have to pass dictionary of kwargs as positional arg to create_endpoint_config

See original GitHub issue

Issue Contrary to documentation, create_endpoint_config does not take keyword arguments, it takes self, args, and kwargs as positional arguments, which requires a call with only kwargs to use None for the args position. This is confusing and should at least be documented properly, but it would be better if the desired behavior listed in the documentation were the true behavior of the code.

Details When I try to use create_endpoint_config to provide an ipv4 address to my container, I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 148, in create_endpoint_config
    return create_endpoint_config(self._version, *args, **kwargs)
TypeError: create_endpoint_config() got an unexpected keyword argument 'ipv4_address'

I’m using the following to create my network config:

new_client = Client(base_url="unix:///var/run/docker.sock")
new_client.start(new_client.create_container(image="nginx",name="test",detach=True,
             networking_config=new_client.create_networking_config({
                  'docker_macvlan':new_client.create_endpoint_config(ipv4_address='10.10.10.14')
             })
))

I tried:

  • new_client.create_endpoint_config(ipv4_address='10.10.10.14')
    • Error as above
  • new_client.create_endpoint_config(kwargs={'ipv4_address':'10.10.10.14'})
    • Similar error as above: unexpected keyword kwargs
  • new_client.create_endpoint_config({'ipv4_address':'10.10.10.14'})
    • JSON parsing error: docker.errors.APIError: 500 Server Error: Internal Server Error ("json: cannot unmarshal string into Go value of type []string")
  • new_client.create_endpoint_config('10.10.10.14')
    • The JSON parsing error again

But the only one that works is new_client.create_endpoint_config(None,{'ipv4_address':'10.10.10.14') due to the fact that the declaration of create_endpoint_config in container.py is def create_container_config(self, *args, **kwargs) where self, _args, and *_kwargs are all positional arguments. These being positional arguments and thus requiring that None in the args position is very strange and makes one’s code less readable.

Furthermore, the documentation says you can use create_endpoint_config as I originally tried, which is simply not the case in my experience.

Client.create_endpoint_config

Create an endpoint config dictionary to be used with Client.create_networking_config.

Params:

aliases (list): A list of aliases for this endpoint. Names in that list can be used within the network to reach the container. Defaults to None. links (list): A list of links for this endpoint. Containers declared in this list will be linked to this container. Defaults to None. ipv4_address (str): The IP address of this container on the network, using the IPv4 protocol. Defaults to None. ipv6_address (str): The IP address of this container on the network, using the IPv6 protocol. Defaults to None. link_local_ips (list): A list of link-local (IPv4/IPv6) addresses. Returns An endpoint config dictionary.

endpoint_config = docker_client.create_endpoint_config(
    aliases=['web', 'app'],
    links=['app_db'],
    ipv4_address='132.65.0.123'
)

Version Info: docker-py==1.8.1 Python 2.7.11

Client: Version: 1.12.0-rc4 API version: 1.24 Go version: go1.6.2 Git commit: e4a0dbc Built: OS/Arch: linux/amd64

Server: Version: 1.12.0-rc4 API version: 1.24 Go version: go1.6.2 Git commit: e4a0dbc Built: OS/Arch: linux/amd64

OS Info: Fedora release 23 (Twenty Three)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
shin-commented, Jul 25, 2016

Your issue is actually much simpler than that. You’re using docker-py 1.8.1, which didn’t support the ipv4_address parameter in create_endpoint_config. The documentation available here is for docker-py 1.9, which is currently at the “release candidate” stage. Sorry about the confusion that may have caused.

I’d suggest using the release candidate (pip install -U docker-py==1.9.0rc2) for now, or wait a few more days for the 1.9.0 release. Alternatively, if you’d rather keep using 1.8.1 for now, you can construct the endpoint_config dictionary yourself.

new_client.start(new_client.create_container(image="nginx",name="test",detach=True,
             networking_config=new_client.create_networking_config({
                  'docker_macvlan': {'IPv4Address': '10.10.10.14'}
             })
))
0reactions
mattarchiecommented, Jul 25, 2016

Oh, I see what you mean. That makes sense - stable vs. latest. I guess I’d just assumed I would the links I followed would give me the stable version and that there would be some kind of banner possibly to warn if you were on latest, just in case.

Thank you for the assistance, I’ll close this ticket now. Looking forward to the new version release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass a dict as a positional argument, not a keyword ...
After familiarizing myself with *args and **kwargs I still seem to be doing something wrong because the event_properties dict doesn't get passed ...
Read more >
How to pass a dict when a Python function expects **kwargs
Many Python functions have a ** kwargs parameter — a dict whose keys and values are populated via keyword arguments. But what if...
Read more >
Python args and kwargs: Demystified
In this example, you're no longer passing a list to my_sum() . Instead, you're passing three different positional arguments. my_sum() takes all the...
Read more >
A Guide to Args, Kwargs, Packing and Unpacking in Python
Args have been packed into a tuple and kwargs a dictionary. ... There are 2 kinds of arguments in Python, positional arguments and...
Read more >
What is unpacking keyword arguments with dictionaries in ...
Positional arguments : These are function arguments that need to be fed to the ... Functions with kwargs can even take in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found