Have to pass dictionary of kwargs as positional arg to create_endpoint_config
See original GitHub issueIssue 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")
- JSON parsing error:
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:
- Created 7 years ago
- Comments:5
Top GitHub Comments
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 theendpoint_config
dictionary yourself.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.