Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e4093ab
Add `target` argument to image building
lawliet89 May 16, 2017
7880c5a
dev version
shin- May 17, 2017
9cc021d
Add support for placement preferences and platforms in TaskTemplate
shin- May 17, 2017
7af7e1b
Merge pull request #1612 from lawliet89/build-stage
shin- May 17, 2017
ff718f5
Add support for ingress in create_network
shin- May 17, 2017
fb16d14
Merge pull request #1615 from docker/service-placement
shin- May 17, 2017
f6f5652
fix type checking for nano_cpus
AlexeyRokhin May 17, 2017
bc69b18
Merge pull request #1619 from docker/AlexeyRokhin-master
shin- May 17, 2017
41aae65
update swarm remove test status code from 500 to >= 400
allencloud May 18, 2017
dc2b24d
Merge pull request #1621 from allencloud/update-swarm-remove-test-sta…
shin- May 22, 2017
45aec93
fix #1625 where ImageCollection.build() could return early with incor…
May 26, 2017
6ef9d42
added integration test for #1625 for ImageCollection.build() that ver…
May 27, 2017
1223fc1
new integration task linting for #1625
May 27, 2017
9eecfb0
Fix misleading build method docs
shin- May 30, 2017
6ae24b9
Add support for ``runtime`` in container create and run API
madhuri-rai07 Jun 1, 2017
5dd91cd
Rewrite the split_port function using re
kaiyou Jun 5, 2017
0c12713
Add a specific unit test for splitting port with IPv6
kaiyou Jun 5, 2017
612c0f3
Fix test cases for ``runtime`` config
madhuri-rai07 Jun 1, 2017
ee75a1c
Ensure default timeout is used by API Client
grahamlyons Jun 8, 2017
ff993dd
Move default `timeout` into `from_env`
grahamlyons Jun 9, 2017
2342961
Only pull the 'latest' tag when testing images
bboreham Jun 14, 2017
ae1f596
excludes requests 2.18.0 from compatible versions
mattoberle Jun 14, 2017
d643a3b
Merge pull request #1644 from bboreham/test-pull-latest
shin- Jun 14, 2017
be0a15a
Merge pull request #1646 from mattoberle/patch-1
shin- Jun 14, 2017
b0c30c8
DockerClient.secrets should be a @property
shin- Jun 14, 2017
1eef700
Merge pull request #1634 from grahamlyons/readtimeout_calling_contain…
shin- Jun 14, 2017
8fc6540
Merge pull request #1647 from docker/1642-dockerclient-secrets
shin- Jun 16, 2017
d33e9ad
Update check_resource decorator to account for new resource names
shin- Jun 16, 2017
c03a009
Raising error in case of invalid value of since kwarg on Container.logs
ChrsMark Jun 16, 2017
d638829
Closes #1588, image.tag does not return anything
osallou Jun 16, 2017
a9d4c7e
Merge pull request #1653 from osallou/master
shin- Jun 16, 2017
e50eacd
Merge pull request #1648 from ChrsMark/master
shin- Jun 16, 2017
87d5cd1
Merge pull request #1632 from kaiyou/master
shin- Jun 16, 2017
2086c20
Merge pull request #1631 from madhuri-rai07/master
shin- Jun 16, 2017
0ac926b
Merge pull request #1629 from shin-/1610-docfix
shin- Jun 16, 2017
8645d1d
Merge pull request #1617 from docker/create-ingress-network
shin- Jun 16, 2017
1ea6618
Add support for start_period in Healthcheck spec
shin- May 18, 2017
75e850e
Merge pull request #1649 from shin-/1639-exec-id-check-resource
shin- Jun 19, 2017
ce8a6ea
Merge pull request #1620 from docker/healthcheck-start-period
shin- Jun 19, 2017
bb82bcf
Merge pull request #1626 from datwiz/images-build-error-1625
shin- Jun 19, 2017
39bb78a
Add network_mode support to Client.build
shin- Jun 19, 2017
0165a34
Add attributes for pickling
AnTuanHa Jun 12, 2017
9b9fb0a
Make sure data is written in prune test so space can be reclaimed
shin- Jun 20, 2017
a962578
Merge pull request #1659 from docker/moby33735
shin- Jun 20, 2017
a3b1059
Merge pull request #1658 from docker/1397-build-network
shin- Jun 20, 2017
06d2553
Add support for ContainerSpec.TTY
shin- Jun 21, 2017
320c810
Support credHelpers section in config.json
shin- Jun 22, 2017
b9e5863
Merge pull request #1640 from zero57/add_attrs_for_pickling
shin- Jun 22, 2017
015fe1c
Correct the description of dns_opt option of create_container
qazbnm456 Dec 20, 2016
28e76a6
Merge pull request #1663 from shin-/qazbnm456-correct_description_of_…
shin- Jun 22, 2017
be8c144
Merge pull request #1662 from docker/1633-credhelpers-support
shin- Jun 22, 2017
15030cb
Merge pull request #1661 from shin-/1622-service-tty
shin- Jun 22, 2017
1ad6859
Bump 2.4.0
shin- Jun 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions docker/api/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
custom_context=False, encoding=None, pull=False,
forcerm=False, dockerfile=None, container_limits=None,
decode=False, buildargs=None, gzip=False, shmsize=None,
labels=None, cache_from=None):
labels=None, cache_from=None, target=None, network_mode=None):
"""
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
needs to be set. ``path`` can be a local path (to a directory
Expand Down Expand Up @@ -88,12 +88,16 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
- cpusetcpus (str): CPUs in which to allow execution, e.g.,
``"0-3"``, ``"0,1"``
decode (bool): If set to ``True``, the returned stream will be
decoded into dicts on the fly. Default ``False``.
decoded into dicts on the fly. Default ``False``
shmsize (int): Size of `/dev/shm` in bytes. The size must be
greater than 0. If omitted the system uses 64MB.
labels (dict): A dictionary of labels to set on the image.
greater than 0. If omitted the system uses 64MB
labels (dict): A dictionary of labels to set on the image
cache_from (list): A list of images used for build cache
resolution.
resolution
target (str): Name of the build-stage to build in a multi-stage
Dockerfile
network_mode (str): networking mode for the run commands during
build

Returns:
A generator for the build output.
Expand Down Expand Up @@ -198,6 +202,22 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
'cache_from was only introduced in API version 1.25'
)

if target:
if utils.version_gte(self._version, '1.29'):
params.update({'target': target})
else:
raise errors.InvalidVersion(
'target was only introduced in API version 1.29'
)

if network_mode:
if utils.version_gte(self._version, '1.25'):
params.update({'networkmode': network_mode})
else:
raise errors.InvalidVersion(
'network_mode was only introduced in API version 1.25'
)

if context is not None:
headers = {'Content-Type': 'application/tar'}
if encoding:
Expand Down
8 changes: 7 additions & 1 deletion docker/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class APIClient(
configuration.
user_agent (str): Set a custom user agent for requests to the server.
"""

__attrs__ = requests.Session.__attrs__ + ['_auth_configs',
'_version',
'base_url',
'timeout']

def __init__(self, base_url=None, version=None,
timeout=DEFAULT_TIMEOUT_SECONDS, tls=False,
user_agent=DEFAULT_USER_AGENT, num_pools=DEFAULT_NUM_POOLS):
Expand Down Expand Up @@ -248,7 +254,7 @@ def _attach_params(self, override=None):
'stream': 1
}

@check_resource
@check_resource('container')
def _attach_websocket(self, container, params=None):
url = self._url("/containers/{0}/attach/ws", container)
req = requests.Request("POST", url, params=self._attach_params(params))
Expand Down
65 changes: 37 additions & 28 deletions docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ContainerApiMixin(object):
@utils.check_resource
@utils.check_resource('container')
def attach(self, container, stdout=True, stderr=True,
stream=False, logs=False):
"""
Expand Down Expand Up @@ -54,7 +54,7 @@ def attach(self, container, stdout=True, stderr=True,

return self._read_from_socket(response, stream)

@utils.check_resource
@utils.check_resource('container')
def attach_socket(self, container, params=None, ws=False):
"""
Like ``attach``, but returns the underlying socket-like object for the
Expand Down Expand Up @@ -93,7 +93,7 @@ def attach_socket(self, container, params=None, ws=False):
)
)

@utils.check_resource
@utils.check_resource('container')
def commit(self, container, repository=None, tag=None, message=None,
author=None, changes=None, conf=None):
"""
Expand Down Expand Up @@ -195,7 +195,7 @@ def containers(self, quiet=False, all=False, trunc=False, latest=False,
x['Id'] = x['Id'][:12]
return res

@utils.check_resource
@utils.check_resource('container')
def copy(self, container, resource):
"""
Identical to the ``docker cp`` command. Get files/folders from the
Expand Down Expand Up @@ -238,7 +238,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
memswap_limit=None, cpuset=None, host_config=None,
mac_address=None, labels=None, volume_driver=None,
stop_signal=None, networking_config=None,
healthcheck=None, stop_timeout=None):
healthcheck=None, stop_timeout=None, runtime=None):
"""
Creates a container. Parameters are similar to those for the ``docker
run`` command except it doesn't support the attach options (``-a``).
Expand Down Expand Up @@ -391,8 +391,6 @@ def create_container(self, image, command=None, hostname=None, user=None,
``{"PASSWORD": "xxx"}``.
dns (:py:class:`list`): DNS name servers. Deprecated since API
version 1.10. Use ``host_config`` instead.
dns_opt (:py:class:`list`): Additional options to be added to the
container's ``resolv.conf`` file
volumes (str or list): List of paths inside the container to use
as volumes.
volumes_from (:py:class:`list`): List of container names or Ids to
Expand All @@ -417,6 +415,9 @@ def create_container(self, image, command=None, hostname=None, user=None,
Default: 10
networking_config (dict): A networking configuration generated
by :py:meth:`create_networking_config`.
runtime (str): Runtime to use with this container.
healthcheck (dict): Specify a test to perform to check that the
container is healthy.

Returns:
A dictionary with an image 'Id' key and a 'Warnings' key.
Expand All @@ -441,7 +442,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
memswap_limit, cpuset, host_config, mac_address, labels,
volume_driver, stop_signal, networking_config, healthcheck,
stop_timeout
stop_timeout, runtime
)
return self.create_container_from_config(config, name)

Expand Down Expand Up @@ -495,6 +496,8 @@ def create_host_config(self, *args, **kwargs):
to have read-write access to the host's ``/dev/sda`` via a
node named ``/dev/xvda`` inside the container.
dns (:py:class:`list`): Set custom DNS servers.
dns_opt (:py:class:`list`): Additional options to be added to the
container's ``resolv.conf`` file
dns_search (:py:class:`list`): DNS search domains.
extra_hosts (dict): Addtional hostnames to resolve inside the
container, as a mapping of hostname to IP address.
Expand Down Expand Up @@ -576,6 +579,7 @@ def create_host_config(self, *args, **kwargs):
values are: ``host``
volumes_from (:py:class:`list`): List of container names or IDs to
get volumes from.
runtime (str): Runtime to use with this container.


Returns:
Expand Down Expand Up @@ -659,7 +663,7 @@ def create_endpoint_config(self, *args, **kwargs):
"""
return EndpointConfig(self._version, *args, **kwargs)

@utils.check_resource
@utils.check_resource('container')
def diff(self, container):
"""
Inspect changes on a container's filesystem.
Expand All @@ -678,7 +682,7 @@ def diff(self, container):
self._get(self._url("/containers/{0}/changes", container)), True
)

@utils.check_resource
@utils.check_resource('container')
def export(self, container):
"""
Export the contents of a filesystem as a tar archive.
Expand All @@ -699,7 +703,7 @@ def export(self, container):
self._raise_for_status(res)
return res.raw

@utils.check_resource
@utils.check_resource('container')
@utils.minimum_version('1.20')
def get_archive(self, container, path):
"""
Expand Down Expand Up @@ -730,7 +734,7 @@ def get_archive(self, container, path):
utils.decode_json_header(encoded_stat) if encoded_stat else None
)

@utils.check_resource
@utils.check_resource('container')
def inspect_container(self, container):
"""
Identical to the `docker inspect` command, but only for containers.
Expand All @@ -750,7 +754,7 @@ def inspect_container(self, container):
self._get(self._url("/containers/{0}/json", container)), True
)

@utils.check_resource
@utils.check_resource('container')
def kill(self, container, signal=None):
"""
Kill a container or send a signal to a container.
Expand All @@ -773,7 +777,7 @@ def kill(self, container, signal=None):

self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def logs(self, container, stdout=True, stderr=True, stream=False,
timestamps=False, tail='all', since=None, follow=None):
"""
Expand Down Expand Up @@ -825,6 +829,11 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
params['since'] = utils.datetime_to_timestamp(since)
elif (isinstance(since, int) and since > 0):
params['since'] = since
else:
raise errors.InvalidArgument(
'since value should be datetime or int, not {}'.
format(type(since))
)
url = self._url("/containers/{0}/logs", container)
res = self._get(url, params=params, stream=stream)
return self._get_result(container, stream, res)
Expand All @@ -836,7 +845,7 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
logs=True
)

@utils.check_resource
@utils.check_resource('container')
def pause(self, container):
"""
Pauses all processes within a container.
Expand All @@ -852,7 +861,7 @@ def pause(self, container):
res = self._post(url)
self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def port(self, container, private_port):
"""
Lookup the public-facing port that is NAT-ed to ``private_port``.
Expand Down Expand Up @@ -901,7 +910,7 @@ def port(self, container, private_port):

return h_ports

@utils.check_resource
@utils.check_resource('container')
@utils.minimum_version('1.20')
def put_archive(self, container, path, data):
"""
Expand Down Expand Up @@ -949,7 +958,7 @@ def prune_containers(self, filters=None):
url = self._url('/containers/prune')
return self._result(self._post(url, params=params), True)

@utils.check_resource
@utils.check_resource('container')
def remove_container(self, container, v=False, link=False, force=False):
"""
Remove a container. Similar to the ``docker rm`` command.
Expand All @@ -973,7 +982,7 @@ def remove_container(self, container, v=False, link=False, force=False):
self._raise_for_status(res)

@utils.minimum_version('1.17')
@utils.check_resource
@utils.check_resource('container')
def rename(self, container, name):
"""
Rename a container. Similar to the ``docker rename`` command.
Expand All @@ -991,7 +1000,7 @@ def rename(self, container, name):
res = self._post(url, params=params)
self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def resize(self, container, height, width):
"""
Resize the tty session.
Expand All @@ -1010,7 +1019,7 @@ def resize(self, container, height, width):
res = self._post(url, params=params)
self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def restart(self, container, timeout=10):
"""
Restart a container. Similar to the ``docker restart`` command.
Expand All @@ -1031,7 +1040,7 @@ def restart(self, container, timeout=10):
res = self._post(url, params=params)
self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def start(self, container, *args, **kwargs):
"""
Start a container. Similar to the ``docker start`` command, but
Expand Down Expand Up @@ -1070,7 +1079,7 @@ def start(self, container, *args, **kwargs):
self._raise_for_status(res)

@utils.minimum_version('1.17')
@utils.check_resource
@utils.check_resource('container')
def stats(self, container, decode=None, stream=True):
"""
Stream statistics for a specific container. Similar to the
Expand All @@ -1096,7 +1105,7 @@ def stats(self, container, decode=None, stream=True):
return self._result(self._get(url, params={'stream': False}),
json=True)

@utils.check_resource
@utils.check_resource('container')
def stop(self, container, timeout=10):
"""
Stops a container. Similar to the ``docker stop`` command.
Expand All @@ -1117,7 +1126,7 @@ def stop(self, container, timeout=10):
timeout=(timeout + (self.timeout or 0)))
self._raise_for_status(res)

@utils.check_resource
@utils.check_resource('container')
def top(self, container, ps_args=None):
"""
Display the running processes of a container.
Expand All @@ -1139,7 +1148,7 @@ def top(self, container, ps_args=None):
params['ps_args'] = ps_args
return self._result(self._get(u, params=params), True)

@utils.check_resource
@utils.check_resource('container')
def unpause(self, container):
"""
Unpause all processes within a container.
Expand All @@ -1152,7 +1161,7 @@ def unpause(self, container):
self._raise_for_status(res)

@utils.minimum_version('1.22')
@utils.check_resource
@utils.check_resource('container')
def update_container(
self, container, blkio_weight=None, cpu_period=None, cpu_quota=None,
cpu_shares=None, cpuset_cpus=None, cpuset_mems=None, mem_limit=None,
Expand Down Expand Up @@ -1217,7 +1226,7 @@ def update_container(
res = self._post_json(url, data=data)
return self._result(res, True)

@utils.check_resource
@utils.check_resource('container')
def wait(self, container, timeout=None):
"""
Block until a container stops, then return its exit code. Similar to
Expand Down
4 changes: 2 additions & 2 deletions docker/api/exec_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ExecApiMixin(object):
@utils.minimum_version('1.15')
@utils.check_resource
@utils.check_resource('container')
def exec_create(self, container, cmd, stdout=True, stderr=True,
stdin=False, tty=False, privileged=False, user='',
environment=None):
Expand Down Expand Up @@ -110,7 +110,7 @@ def exec_resize(self, exec_id, height=None, width=None):
self._raise_for_status(res)

@utils.minimum_version('1.15')
@utils.check_resource
@utils.check_resource('exec_id')
def exec_start(self, exec_id, detach=False, tty=False, stream=False,
socket=False):
"""
Expand Down
Loading