internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: docker/docker-py

Issue:
Check resource error in container network API
```
docker python client v2.4.2
python v2.7.12
docker v17.03.1-ce
Ubuntu 16.04
```

PR #1649 updated the `check_resource` decorator to handle different resource names.  Container network API functions  `connect_container_to_network()` and `disconnect_container_from_network()` check 'image' as resource ID and not 'container'.

Reproduce using the following snippet:
```python
import docker

cli = docker.APIClient(base_url='unix:///var/run/docker.sock')
cli.pull(repository='ubuntu', tag='latest')

name = 'my_ubuntu'
container = cli.create_container(image='ubuntu:latest', name=name)
cli.connect_container_to_network(container=name, net_id='bridge')
```

This causes:
```
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    cli.connect_container_to_network(container=name, net_id='bridge')
  File "/home/mberry/scratch/virtualenv/docker_py/local/lib/python2.7/site-packages/docker/utils/decorators.py", line 17, in wrapped
    'Resource ID was not provided'
docker.errors.NullResource: Resource ID was not provided
```
client.networks.create check_duplicates docs not reflective of behavior
Docs say it does, but it's actually set to `None`.


Discussion:

Resolving patch:
diff --git a/docker/transport/unixconn.py b/docker/transport/unixconn.py
--- a/docker/transport/unixconn.py
+++ b/docker/transport/unixconn.py
@@ -21,13 +21,12 @@
 class UnixHTTPResponse(httplib.HTTPResponse, object):
     def __init__(self, sock, *args, **kwargs):
         disable_buffering = kwargs.pop('disable_buffering', False)
+        if six.PY2:
+            # FIXME: We may need to disable buffering on Py3 as well,
+            # but there's no clear way to do it at the moment. See:
+            # https://github.com/docker/docker-py/issues/1799
+            kwargs['buffering'] = not disable_buffering
         super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)
-        if disable_buffering is True:
-            # We must first create a new pointer then close the old one
-            # to avoid closing the underlying socket.
-            new_fp = sock.makefile('rb', 0)
-            self.fp.close()
-            self.fp = new_fp
 
 
 class UnixHTTPConnection(httplib.HTTPConnection, object):
diff --git a/docker/version.py b/docker/version.py
--- a/docker/version.py
+++ b/docker/version.py
@@ -1,2 +1,2 @@
-version = "2.6.0"
+version = "2.6.1"
 version_info = tuple([int(d) for d in version.split("-")[0].split(".")])


Test patch:
Repository: docker/docker-py

Issue:
Log message not replacing string format placeholder
[This line](https://github.com/docker/docker-py/blob/e9fab1432b974ceaa888b371e382dfcf2f6556e4/docker/auth.py#L205) in the `parse_auth` function in `auth.py` is using a string format placeholder but is not calling `format` on the string to replace it.


Discussion:

Resolving patch:
diff --git a/docker/auth.py b/docker/auth.py
--- a/docker/auth.py
+++ b/docker/auth.py
@@ -203,7 +203,7 @@ def parse_auth(entries, raise_on_error=False):
             # https://github.com/docker/compose/issues/3265
             log.debug(
                 'Auth data for {0} is absent. Client might be using a '
-                'credentials store instead.'
+                'credentials store instead.'.format(registry)
             )
             conf[registry] = {}
             continue


Test patch:
Repository: docker/docker-py

Issue:
Deleting a volume with volume name containing blanks failed using docker python sdk
Description:
Creating a volume with the volume name contains a blank successfully，but delete the volume failed. When deleting the volume that the name contains a blank, the blank is decoded to "+". 
Steps to Reproduce:
1. Create a docker python client
2. Create a volume with name "vo1 test_-" using the client
3. List volumes using the client
4. Delete the volume "vo1 test_-" using the client
The command and errors:
>>> import docker
>>> client = docker.DockerClient(base_url='tcp://ci-docker-node1:2375')
>>> client.volumes.create(name='vo1 test_-', driver='ubiquity', driver_opts={'size': "5", 'profile': 'gold'})
<Volume: vo1 test_->
>>> created_volume=client.volumes.list()
>>> created_volume
[<Volume: vo1 test_->]
>>> created_volume[0].remove()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/wangyd/xenv/lib/python2.7/site-packages/docker/models/volumes.py", line 25, in remove
    return self.client.api.remove_volume(self.id, force=force)
  File "/Users/wangyd/xenv/lib/python2.7/site-packages/docker/utils/decorators.py", line 34, in wrapper
    return f(self, *args, **kwargs)
  File "/Users/wangyd/xenv/lib/python2.7/site-packages/docker/api/volume.py", line 165, in remove_volume
    self._raise_for_status(resp)
  File "/Users/wangyd/xenv/lib/python2.7/site-packages/docker/api/client.py", line 222, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/Users/wangyd/xenv/lib/python2.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.NotFound: 404 Client Error: Not Found ("get vo1+test_-: no such volume")
>>> 



Discussion:
Thanks for the report, we'll look into it!

Resolving patch:
diff --git a/docker/api/client.py b/docker/api/client.py
--- a/docker/api/client.py
+++ b/docker/api/client.py
@@ -206,7 +206,7 @@ def _url(self, pathfmt, *args, **kwargs):
                     'instead'.format(arg, type(arg))
                 )
 
-        quote_f = partial(six.moves.urllib.parse.quote_plus, safe="/:")
+        quote_f = partial(six.moves.urllib.parse.quote, safe="/:")
         args = map(quote_f, args)
 
         if kwargs.get('versioned_api', True):


Test patch:
diff --git a/tests/integration/api_network_test.py b/tests/integration/api_network_test.py
--- a/tests/integration/api_network_test.py
+++ b/tests/integration/api_network_test.py
@@ -484,3 +484,10 @@ def test_create_inspect_network_with_scope(self):
         assert self.client.inspect_network(net_name_swarm, scope='swarm')
         with pytest.raises(docker.errors.NotFound):
             self.client.inspect_network(net_name_swarm, scope='local')
+
+    @requires_api_version('1.21')
+    def test_create_remove_network_with_space_in_name(self):
+        net_id = self.client.create_network('test 01')
+        self.tmp_networks.append(net_id)
+        assert self.client.inspect_network('test 01')
+        assert self.client.remove_network('test 01') is None  # does not raise
Repository: docker/docker-py

Issue:
.dockerignore file with space-only lines breaks build on Windows
Originally reported in https://github.com/docker/compose/issues/5526


Discussion:

Resolving patch:
diff --git a/docker/api/build.py b/docker/api/build.py
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -145,7 +145,9 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
             exclude = None
             if os.path.exists(dockerignore):
                 with open(dockerignore, 'r') as f:
-                    exclude = list(filter(bool, f.read().splitlines()))
+                    exclude = list(filter(
+                        bool, [l.strip() for l in f.read().splitlines()]
+                    ))
             context = utils.tar(
                 path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
             )


Test patch:
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py
--- a/tests/integration/api_build_test.py
+++ b/tests/integration/api_build_test.py
@@ -352,6 +352,28 @@ def test_build_gzip_encoding(self):
 
         assert 'Successfully built' in lines[-1]['stream']
 
+    def test_build_with_dockerfile_empty_lines(self):
+        base_dir = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, base_dir)
+        with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f:
+            f.write('FROM busybox\n')
+        with open(os.path.join(base_dir, '.dockerignore'), 'w') as f:
+            f.write('\n'.join([
+                '   ',
+                '',
+                '\t\t',
+                '\t     ',
+            ]))
+
+        stream = self.client.build(
+            path=base_dir, stream=True, decode=True, nocache=True
+        )
+
+        lines = []
+        for chunk in stream:
+            lines.append(chunk)
+        assert 'Successfully built' in lines[-1]['stream']
+
     def test_build_gzip_custom_encoding(self):
         with self.assertRaises(errors.DockerException):
             self.client.build(path='.', gzip=True, encoding='text/html')
Repository: docker/docker-py

Issue:
swarm.init() does not return a value
No return value unlike as specified in documentation. 


Discussion:

Resolving patch:
diff --git a/docker/models/swarm.py b/docker/models/swarm.py
--- a/docker/models/swarm.py
+++ b/docker/models/swarm.py
@@ -112,6 +112,7 @@ def init(self, advertise_addr=None, listen_addr='0.0.0.0:2377',
         init_kwargs['swarm_spec'] = self.client.api.create_swarm_spec(**kwargs)
         self.client.api.init_swarm(**init_kwargs)
         self.reload()
+        return True
 
     def join(self, *args, **kwargs):
         return self.client.api.join_swarm(*args, **kwargs)


Test patch:
Repository: docker/docker-py

Issue:
Support OpenSSH's IdentityFile config option
# Description
As a developer I want `docker-py` to load the identity file according to my setting specified in `~/.ssh/config`, not only the "default" `id_rsa` file.

# Example
I have a `~/.ssh/config` file with contents:
```ssh
Host myHost
    User myUser
    HostName myIp
    IdentityFile C:/Users/me/.ssh/id_rsa_custom_file
    IdentitiesOnly yes
```

Now I would like `docker-py` to pick up `C:/Users/me/.ssh/id_rsa_custom_file` for trying to connect to the remote host (For example when I want to run `docker-compose -H "ssh://myHost" ps`. However right now it does not.

When I rename `C:/Users/me/.ssh/id_rsa_custom_file` to `C:/Users/me/.ssh/id_rsa` it works just fine. However this is not an option for me since I have multiple identity files and hosts that I want to use.

# Proposal
Add something like this to the [`sshcon.py`](https://github.com/docker/docker-py/blob/c285bee1bc59f6b2d65cee952b5522c88047a3bc/docker/transport/sshconn.py#L105):
```python
if 'identityfile' in host_config:
    self.ssh_params['key_filename '] = host_config['identityfile']
```


Discussion:

Resolving patch:
diff --git a/docker/transport/sshconn.py b/docker/transport/sshconn.py
--- a/docker/transport/sshconn.py
+++ b/docker/transport/sshconn.py
@@ -100,6 +100,8 @@ def __init__(self, base_url, timeout=60,
                 )
             if 'hostname' in host_config:
                 self.ssh_params['hostname'] = host_config['hostname']
+            if 'identityfile' in host_config:
+                self.ssh_params['key_filename'] = host_config['identityfile']
             if base_url.port is None and 'port' in host_config:
                 self.ssh_params['port'] = self.ssh_conf['port']
             if base_url.username is None and 'user' in host_config:


Test patch:
Repository: docker/docker-py

Issue:
More detailed documentation for healthcheck with run
The `run` method on `client.containers` has an argument `healthcheck`. However, apart from that it is given as a dict there is few documentation. I looked in the `Healthcheck` class and guessed that the content of the dict equals to the arguments of this class, which is the case. I think it would be helpful to either refer to the `Healthcheck` class or to write a similar documentation for this.


Discussion:
Hi @JanoschDeurer 
Maybe the [docker api documentation](https://docs.docker.com/engine/api/v1.40/#operation/ContainerCreate) can help you.
Hey @feliperuhland, thanks for the response :) I had already found out how to use the healthcheck. My ticket was only about the documentation. I think a simple reference to the healthcheck class would suffice.
Ok, sorry about that. What do you think to write a pull request for that?

Resolving patch:
diff --git a/docker/models/containers.py b/docker/models/containers.py
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -593,7 +593,27 @@ def run(self, image, command=None, stdout=True, stderr=False,
             group_add (:py:class:`list`): List of additional group names and/or
                 IDs that the container process will run as.
             healthcheck (dict): Specify a test to perform to check that the
-                container is healthy.
+                container is healthy. The dict takes the following keys:
+                - test (:py:class:`list` or str): Test to perform to determine
+                    container health. Possible values:
+
+                    - Empty list: Inherit healthcheck from parent image
+                    - ``["NONE"]``: Disable healthcheck
+                    - ``["CMD", args...]``: exec arguments directly.
+                    - ``["CMD-SHELL", command]``: Run command in the system's
+                      default shell.
+
+                    If a string is provided, it will be used as a ``CMD-SHELL``
+                    command.
+                - interval (int): The time to wait between checks in
+                  nanoseconds. It should be 0 or at least 1000000 (1 ms).
+                - timeout (int): The time to wait before considering the check
+                  to have hung. It should be 0 or at least 1000000 (1 ms).
+                - retries (int): The number of consecutive failures needed to
+                    consider a container as unhealthy.
+                - start_period (int): Start period for the container to
+                    initialize before starting health-retries countdown in
+                    nanoseconds. It should be 0 or at least 1000000 (1 ms).
             hostname (str): Optional hostname for the container.
             init (bool): Run an init inside the container that forwards
                 signals and reaps processes


Test patch:
Repository: docker/docker-py

Issue:
Plugin model upgrade: object has no attribute '_reload'
I've already got a fix for this that I'm about to submit. For reference, here are the steps to reproduce in ipython:
```
~$ ipython                                                                     [venv]
Python 3.7.6 (default, Dec 22 2019, 01:09:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import docker

In [2]: c = docker.DockerClient(base_url='unix://var/run/docker.sock')

In [3]: p = c.plugins.get('loki')

In [4]: list(p.upgrade("grafana/loki-docker-driver:latest"))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-e5fc26fa0514> in <module>
----> 1 list(p.upgrade("grafana/loki-docker-driver:latest"))

~/venv/lib/python3.7/site-packages/docker/models/plugins.py in upgrade(self, remote)
    120         for d in self.client.api.upgrade_plugin(self.name, remote, privileges):
    121             yield d
--> 122         self._reload()
    123
    124

AttributeError: 'Plugin' object has no attribute '_reload'
```

```
docker==4.3.1
Python 3.7.6
Client: Docker Engine - Community
 Cloud integration  0.1.18
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 16:58:31 2020
 OS/Arch:           darwin/amd64
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:07:04 2020
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.3.7
  GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
```


Discussion:

Resolving patch:
diff --git a/docker/models/plugins.py b/docker/models/plugins.py
--- a/docker/models/plugins.py
+++ b/docker/models/plugins.py
@@ -119,7 +119,7 @@ def upgrade(self, remote=None):
         privileges = self.client.api.plugin_privileges(remote)
         for d in self.client.api.upgrade_plugin(self.name, remote, privileges):
             yield d
-        self._reload()
+        self.reload()
 
 
 class PluginCollection(Collection):


Test patch:
Repository: docker/docker-py

Issue:
version requirements for cryptography should be consistent
Hi
It seems that version requirements for cryptography in setup.py and requirements.txt are not consistent
In setup.py, it is cryptography>=1.3.4
In requirements.txt, it is cryptography==3.2
Note that in pypi, the version of cryptography is always updating( now 3.4.6). Inconsistent version requirements will result in installing different version for cryptography if I use different  ways of installation. 


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@
     # https://github.com/pypa/pip/issues/4391).  Once that's fixed, instead of
     # installing the extra dependencies, install the following instead:
     # 'requests[security] >= 2.5.2, != 2.11.0, != 2.12.2'
-    'tls': ['pyOpenSSL>=17.5.0', 'cryptography>=1.3.4', 'idna>=2.0.0'],
+    'tls': ['pyOpenSSL>=17.5.0', 'cryptography>=3.4.7', 'idna>=2.0.0'],
 
     # Only required when connecting using the ssh:// protocol
     'ssh': ['paramiko>=2.4.2'],


Test patch:
Repository: docker/docker-py

Issue:
Bring back support OpenSSH Identityfile
# Description

Support for identity file was added in - #2534
And then removed during refactoring in - #2691 

# Proposal

Add it back :) in PR #2846

### General Info

```bash
❯❯❯ docker --version
Docker version 20.10.6, build 370c289

❯❯❯ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
```
MacOS 11.3.1



Discussion:

Resolving patch:
diff --git a/docker/transport/sshconn.py b/docker/transport/sshconn.py
--- a/docker/transport/sshconn.py
+++ b/docker/transport/sshconn.py
@@ -205,7 +205,6 @@ def _create_paramiko_client(self, base_url):
             with open(ssh_config_file) as f:
                 conf.parse(f)
             host_config = conf.lookup(base_url.hostname)
-            self.ssh_conf = host_config
             if 'proxycommand' in host_config:
                 self.ssh_params["sock"] = paramiko.ProxyCommand(
                     self.ssh_conf['proxycommand']
@@ -213,9 +212,11 @@ def _create_paramiko_client(self, base_url):
             if 'hostname' in host_config:
                 self.ssh_params['hostname'] = host_config['hostname']
             if base_url.port is None and 'port' in host_config:
-                self.ssh_params['port'] = self.ssh_conf['port']
+                self.ssh_params['port'] = host_config['port']
             if base_url.username is None and 'user' in host_config:
-                self.ssh_params['username'] = self.ssh_conf['user']
+                self.ssh_params['username'] = host_config['user']
+            if 'identityfile' in host_config:
+                self.ssh_params['key_filename'] = host_config['identityfile']
 
         self.ssh_client.load_system_host_keys()
         self.ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy())


Test patch:
Repository: docker/docker-py

Issue:
exec_run: filedescriptor out of range in select() (python3)
The following code works with python2, but throws error on python3:
```
import docker

files = [open('/tmp/test_' + str(i), 'w+b') for i in range(0, 1024)]
client = docker.from_env()
cnt = client.containers.run("ubuntu:18.04", command="sleep 10", detach=True, auto_remove=True)
cnt.exec_run("ls -ls")
```
Output: 
```  File "var/dockerpy_bug.py", line 6, in <module>
    cnt.exec_run("ls -ls")
  File "/usr/lib/python3/dist-packages/docker/models/containers.py", line 185, in exec_run
    resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
  File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/docker/api/exec_api.py", line 165, in exec_start
    return self._read_from_socket(res, stream, tty)
  File "/usr/lib/python3/dist-packages/docker/api/client.py", line 377, in _read_from_socket
    return six.binary_type().join(gen)
  File "/usr/lib/python3/dist-packages/docker/utils/socket.py", line 75, in frames_iter
    n = next_frame_size(socket)
  File "/usr/lib/python3/dist-packages/docker/utils/socket.py", line 62, in next_frame_size
    data = read_exactly(socket, 8)
  File "/usr/lib/python3/dist-packages/docker/utils/socket.py", line 47, in read_exactly
    next_data = read(socket, n - len(data))
  File "/usr/lib/python3/dist-packages/docker/utils/socket.py", line 27, in read
    select.select([socket], [], [])
ValueError: filedescriptor out of range in select()
```
if socket has fd > 1024, select will fail
Stack Overflow suggests using poll() in place of select(), as it's not bound by 1024 fd limit.

Environment :
ubuntu: 18.04
docker: 18.09.3
docker API: 1.39
python: 3.6.7
docker-py: 3.7.0


Discussion:

Resolving patch:
diff --git a/docker/utils/socket.py b/docker/utils/socket.py
--- a/docker/utils/socket.py
+++ b/docker/utils/socket.py
@@ -3,6 +3,7 @@
 import select
 import socket as pysocket
 import struct
+import sys
 
 try:
     from ..transport import NpipeSocket
@@ -31,7 +32,13 @@ def read(socket, n=4096):
     recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)
 
     if not isinstance(socket, NpipeSocket):
-        select.select([socket], [], [])
+        if sys.platform == 'win32':
+            # Limited to 1024
+            select.select([socket], [], [])
+        else:
+            poll = select.poll()
+            poll.register(socket)
+            poll.poll()
 
     try:
         if hasattr(socket, 'recv'):


Test patch:
Repository: docker/docker-py

Issue:
question: where is the documentation of the `gzip` option?
Where is the documentation of the `gzip` option on BuildApiMixin?

https://github.com/docker/docker-py/blob/master/docker/api/build.py#L61-L111


Discussion:
Looks like it's missing. Please submit a PR! 😄 

Resolving patch:
diff --git a/docker/api/build.py b/docker/api/build.py
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -76,6 +76,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
             forcerm (bool): Always remove intermediate containers, even after
                 unsuccessful builds
             dockerfile (str): path within the build context to the Dockerfile
+            gzip (bool): If set to ``True``, gzip compression/encoding is used
             buildargs (dict): A dictionary of build arguments
             container_limits (dict): A dictionary of limits applied to each
                 container created by the build process. Valid keys:


Test patch: