Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions docker/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def get_archive(self, container, path, chunk_size=DEFAULT_DATA_CHUNK_SIZE,
)

@utils.check_resource('container')
def inspect_container(self, container):
def inspect_container(self, container, size=False):
"""
Identical to the `docker inspect` command, but only for containers.

Expand All @@ -790,8 +790,9 @@ def inspect_container(self, container):
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
params = {"size": "true" if size else "false"}
return self._result(
self._get(self._url("/containers/{0}/json", container)), True
self._get(self._url("/containers/{0}/json", container), params=params), True
)

@utils.check_resource('container')
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,18 @@ def test_inspect_container(self):
fake_request.assert_called_with(
'GET',
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
timeout=DEFAULT_TIMEOUT_SECONDS
timeout=DEFAULT_TIMEOUT_SECONDS,
params={'size': 'false'}
)

def test_inspect_container_with_size(self):
self.client.inspect_container(fake_api.FAKE_CONTAINER_ID, size=True)

fake_request.assert_called_with(
'GET',
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
timeout=DEFAULT_TIMEOUT_SECONDS,
params={'size': 'true'}
)

def test_inspect_container_undefined_id(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def post_fake_create_container():
return status_code, response


def get_fake_inspect_container(tty=False):
def get_fake_inspect_container(tty=False, size=False):
status_code = 200
response = {
'Id': FAKE_CONTAINER_ID,
Expand All @@ -167,6 +167,11 @@ def get_fake_inspect_container(tty=False):
},
"MacAddress": "02:42:ac:11:00:0a"
}
if size:
response.update({
"SizeRw": 50178,
"SizeRootFs": 152129365
})
return status_code, response


Expand Down