docker-py: get_config_header error on mac

Thanks in advance for the help

client = docker.from_env()
client.containers.run("ubuntu", "echo hello world")

/usr/local/lib/python2.7/site-packages/docker/models/containers.pyc in run(self, image, command, stdout, stderr, remove, **kwargs)
    653                                     detach=detach, **kwargs)
    654         except ImageNotFound:
--> 655             self.client.images.pull(image)
    656             container = self.create(image=image, command=command,
    657                                     detach=detach, **kwargs)

/usr/local/lib/python2.7/site-packages/docker/models/images.pyc in pull(self, name, **kwargs)
    254             >>> image = client.images.pull('busybox')
    255         """
--> 256         self.client.api.pull(name, **kwargs)
    257         return self.get(name)
    258 

/usr/local/lib/python2.7/site-packages/docker/api/image.pyc in pull(self, repository, tag, stream, insecure_registry, auth_config, decode)
    331         if utils.compare_version('1.5', self._version) >= 0:
    332             if auth_config is None:
--> 333                 header = auth.get_config_header(self, registry)
    334                 if header:
    335                     headers['X-Registry-Auth'] = header

AttributeError: 'module' object has no attribute 'get_config_header'

What am I doing wrong?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

You may need to uninstall the docker-py package as it may be conflicting with the new docker package.

pip uninstall docker docker-py
pip install docker

Let me know if it helps.

So, I fixed this by removing the leftover files after an upgrade

rm -rf YOUR-PYTHON/site-packages/docker/auth/

I have upgraded from 1.6 to 2.4.2


Long story here

I got this error when I try to run a container for an image which does not exists.

here is the test_docker.py code

import docker
client = docker.DockerClient(
    base_url='tcp://localhost:2375',
    version='1.24',
    timeout=2,
    tls=False,
    )
client.containers.run(
    image='no-such-image:exp',
    detach=True
    )

and here is the output

$ ./build-ubuntu1604-x64/bin/python test_docker.py 
Traceback (most recent call last):
  File "test_docker.py", line 10, in <module>
    detach=True
  File "/home/adi/chevah/server/build-ubuntu1604-x64/lib/python2.7/site-packages/docker/models/containers.py", line 699, in run
    self.client.images.pull(image)
  File "/home/adi/chevah/server/build-ubuntu1604-x64/lib/python2.7/site-packages/docker/models/images.py", line 273, in pull
    self.client.api.pull(name, tag=tag, **kwargs)
  File "/home/adi/chevah/server/build-ubuntu1604-x64/lib/python2.7/site-packages/docker/api/image.py", line 358, in pull
    header = auth.get_config_header(self, registry)
AttributeError: 'module' object has no attribute 'get_config_header'

I done some debugging and i got

(Pdb) auth.__file__
(Pdb) '/home/adi/chevah/server/build-ubuntu1604-x64/lib/python2.7/site-packages/docker/auth/__init__.pyc'
dir(auth)
(Pdb) ['INDEX_NAME', 'INDEX_URL', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'auth', 'encode_header', 'load_config', 'resolve_authconfig', 'resolve_repository_name']

While checking the upstream code for release 2.4.2 https://github.com/docker/docker-py/tree/2.4.2-release/docker I saw that there is no auth package… only a module.

So, it looks like the trouble is from a bad upgrade.

Manual cleanup and all is good 😃


My versions

docker==2.4.2
docker-py==1.10.6
docker-pycreds==0.2.1
Python 2.7.12
Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   78d1802
 Built:        Tue Jan 31 23:35:14 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:19:04 2017
 OS/Arch:      linux/amd64

@IoTPlay docker-compose depends on docker, not on docker-py - so installing docker-py beforehand will ensure a broken install in all cases,

please skip docker-py

@shin- i can replicate the issue.

docker-py was installed, pip install docker would use the wheel and not catch the error $ pip install docker-py docker will succeed, afterwards i get

E               AttributeError: 'module' object has no attribute 'get_config_header'

.../site-packages/docker/api/image.py:358: AttributeError
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> .../site-packages/docker/api/image.py(358)pull()
-> header = auth.get_config_header(self, registry)
(Pdb) auth
<module 'docker.auth' from '.../site-packages/docker/auth/__init__.pyc'>
(Pdb) auth.auth
<module 'docker.auth.auth' from '.../site-packages/docker/auth/auth.pyc'>
(Pdb) 

its only fixable by uninstalling both packages and reinstalling docker

in order to protect users i suggest to move the check from setup.py to docker/__init__.py in modern times setup.py is not executed at all since pip uses wheels if possible and aggressively caches wheels locally as well