Repository: docker/docker-py

Issue:
Pull image with tag fails
library version: 2.2.1
docker version: 1.23
Repro steps:
- remove busy box images if any
- pull busy box image with tag = 1
`docker.from_env(version='auto').images.pull('busybox', tag='1')`
Gives
`docker.errors.ImageNotFound: 404 Client Error: Not Found ("No such image: busybox")`


Discussion:
Thanks for the report. See my comment there for a workaround: https://github.com/docker/docker-py/issues/1548#issuecomment-297853720

Resolving patch:
diff --git a/docker/models/images.py b/docker/models/images.py
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -238,7 +238,7 @@ def load(self, data):
         """
         return self.client.api.load_image(data)
 
-    def pull(self, name, **kwargs):
+    def pull(self, name, tag=None, **kwargs):
         """
         Pull an image of the given name and return it. Similar to the
         ``docker pull`` command.
@@ -267,8 +267,8 @@ def pull(self, name, **kwargs):
 
             >>> image = client.images.pull('busybox')
         """
-        self.client.api.pull(name, **kwargs)
-        return self.get(name)
+        self.client.api.pull(name, tag=tag, **kwargs)
+        return self.get('{0}:{1}'.format(name, tag) if tag else name)
 
     def push(self, repository, tag=None, **kwargs):
         return self.client.api.push(repository, tag=tag, **kwargs)


Test patch:
diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py
--- a/tests/integration/models_images_test.py
+++ b/tests/integration/models_images_test.py
@@ -30,10 +30,12 @@ def test_build_with_error(self):
 
     def test_build_with_multiple_success(self):
         client = docker.from_env(version=TEST_API_VERSION)
-        image = client.images.build(tag='some-tag', fileobj=io.BytesIO(
-            "FROM alpine\n"
-            "CMD echo hello world".encode('ascii')
-            ))
+        image = client.images.build(
+            tag='some-tag', fileobj=io.BytesIO(
+                "FROM alpine\n"
+                "CMD echo hello world".encode('ascii')
+            )
+        )
         self.tmp_imgs.append(image.id)
         assert client.containers.run(image) == b"hello world\n"
 
@@ -53,6 +55,11 @@ def test_pull(self):
         image = client.images.pull('alpine:latest')
         assert 'alpine:latest' in image.attrs['RepoTags']
 
+    def test_pull_with_tag(self):
+        client = docker.from_env(version=TEST_API_VERSION)
+        image = client.images.pull('alpine', tag='3.3')
+        assert 'alpine:3.3' in image.attrs['RepoTags']
+
 
 class ImageTest(BaseIntegrationTest):
 
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py
--- a/tests/unit/models_containers_test.py
+++ b/tests/unit/models_containers_test.py
@@ -227,7 +227,7 @@ def test_run_pull(self):
         container = client.containers.run('alpine', 'sleep 300', detach=True)
 
         assert container.id == FAKE_CONTAINER_ID
-        client.api.pull.assert_called_with('alpine')
+        client.api.pull.assert_called_with('alpine', tag=None)
 
     def test_run_with_error(self):
         client = make_fake_client()
diff --git a/tests/unit/models_images_test.py b/tests/unit/models_images_test.py
--- a/tests/unit/models_images_test.py
+++ b/tests/unit/models_images_test.py
@@ -42,7 +42,7 @@ def test_load(self):
     def test_pull(self):
         client = make_fake_client()
         image = client.images.pull('test_image')
-        client.api.pull.assert_called_with('test_image')
+        client.api.pull.assert_called_with('test_image', tag=None)
         client.api.inspect_image.assert_called_with('test_image')
         assert isinstance(image, Image)
         assert image.id == FAKE_IMAGE_ID