Skip to content

Fixed in #605 - Client.inspect_image("") behaves like Client.images() #602

@posita

Description

@posita
>>> from os import environ
>>> from docker import Client
>>> c = Client(environ['DOCKER_HOST'])
>>> type(c.images())
<type 'list'>
>>> >>> len(c.images()) > 0
True
>>> c.inspect_image('') == c.images()
True

This isn't hard to see why. inspect_image() calls /images/{image_id}/json. images() calls /images/json. Where the {image_id} is an empty string, the resulting URL for the call to inspect_image() is /images//json:

% [ "$( curl --location --post30{1,2,3} --silent 'http://<host>:2375/images//json' -H 'Content-Type: application/json' -H 'Accept: application/json' -X GET )" \
> = "$( curl --location --post30{1,2,3} --silent 'http://<host>:2375/images/json' -H 'Content-Type: application/json' -H 'Accept: application/json' -X GET )" ] \
> && echo 'SAME' || echo 'NOT THE SAME'
SAME

By analogy, I suspect the inspect_container() and containers() methods suffer from a similar problem.

The expected format of the inspect_*() methods (a detailed object) is different from the corresponding *s() methods (an array of summary objects), so it seems to me calling inspect_*("") should probably raise an exception. Maybe something like:

    @check_resource
    def inspect_container(self, container):
        ...
        if not container:
            raise ValueError('container ID required')
        ...

    @check_resource
    def inspect_image(self, image):
        ...
        if not image:
            raise ValueError('image ID required')
        ...

I can create a PR if desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions