Skip to content

Commit c6ddea4

Browse files
committed
Include tag in images.get after pulling if provided separately
Signed-off-by: Joffrey F <[email protected]>
1 parent 05741a1 commit c6ddea4

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

docker/models/images.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def load(self, data):
238238
"""
239239
return self.client.api.load_image(data)
240240

241-
def pull(self, name, **kwargs):
241+
def pull(self, name, tag=None, **kwargs):
242242
"""
243243
Pull an image of the given name and return it. Similar to the
244244
``docker pull`` command.
@@ -267,8 +267,8 @@ def pull(self, name, **kwargs):
267267
268268
>>> image = client.images.pull('busybox')
269269
"""
270-
self.client.api.pull(name, **kwargs)
271-
return self.get(name)
270+
self.client.api.pull(name, tag=tag, **kwargs)
271+
return self.get('{0}:{1}'.format(name, tag) if tag else name)
272272

273273
def push(self, repository, tag=None, **kwargs):
274274
return self.client.api.push(repository, tag=tag, **kwargs)

tests/integration/models_images_test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def test_build_with_error(self):
3030

3131
def test_build_with_multiple_success(self):
3232
client = docker.from_env(version=TEST_API_VERSION)
33-
image = client.images.build(tag='some-tag', fileobj=io.BytesIO(
34-
"FROM alpine\n"
35-
"CMD echo hello world".encode('ascii')
36-
))
33+
image = client.images.build(
34+
tag='some-tag', fileobj=io.BytesIO(
35+
"FROM alpine\n"
36+
"CMD echo hello world".encode('ascii')
37+
)
38+
)
3739
self.tmp_imgs.append(image.id)
3840
assert client.containers.run(image) == b"hello world\n"
3941

@@ -53,6 +55,11 @@ def test_pull(self):
5355
image = client.images.pull('alpine:latest')
5456
assert 'alpine:latest' in image.attrs['RepoTags']
5557

58+
def test_pull_with_tag(self):
59+
client = docker.from_env(version=TEST_API_VERSION)
60+
image = client.images.pull('alpine', tag='3.3')
61+
assert 'alpine:3.3' in image.attrs['RepoTags']
62+
5663

5764
class ImageTest(BaseIntegrationTest):
5865

tests/unit/models_containers_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def test_run_pull(self):
227227
container = client.containers.run('alpine', 'sleep 300', detach=True)
228228

229229
assert container.id == FAKE_CONTAINER_ID
230-
client.api.pull.assert_called_with('alpine')
230+
client.api.pull.assert_called_with('alpine', tag=None)
231231

232232
def test_run_with_error(self):
233233
client = make_fake_client()

tests/unit/models_images_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_load(self):
4242
def test_pull(self):
4343
client = make_fake_client()
4444
image = client.images.pull('test_image')
45-
client.api.pull.assert_called_with('test_image')
45+
client.api.pull.assert_called_with('test_image', tag=None)
4646
client.api.inspect_image.assert_called_with('test_image')
4747
assert isinstance(image, Image)
4848
assert image.id == FAKE_IMAGE_ID

0 commit comments

Comments
 (0)