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?
Same problem here on Ubuntu Server when trying to pull an image.
Here more information:
docker==2.0.0
docker-py==1.10.6
docker-pycreds==0.2.1
Python 2.7.12
Client:
Version: 1.12.4
API version: 1.24
Go version: go1.6.4
Git commit: 1564f02
Built: Tue Dec 13 00:08:34 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.4
API version: 1.24
Go version: go1.6.4
Git commit: 1564f02
Built: Tue Dec 13 00:08:34 2016
OS/Arch: linux/amd64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
Here a snippet to reproduce the issue on my system:
>>> import logging
>>> import docker
>>> logging.basicConfig(level=logging.DEBUG)
>>> cli = docker.from_env(assert_hostname=False)
DEBUG:docker.auth.auth:Trying paths: ['/home/mkcroiser/.docker/config.json', '/home/mkcroiser/.dockercfg']
DEBUG:docker.auth.auth:No config file found
>>> cli.images.pull("busybox")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mkcroiser/.local/lib/python2.7/site-packages/docker/models/images.py", line 256, in pull
self.client.api.pull(name, **kwargs)
File "/home/mkcroiser/.local/lib/python2.7/site-packages/docker/api/image.py", line 333, in pull
header = auth.get_config_header(self, registry)
AttributeError: 'module' object has no attribute 'get_config_header'
Hey folks, please heed the following recommendations when reporting issues: https://github.com/docker/docker-py/blob/master/CONTRIBUTING.md#reporting-issues
I can't help you if I don't know what version you're running.
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.
Hi @shin- , thanks a lot for your help it works again now!
I have same problem, @shin- Thanks.
@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
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
Hi, is this still an open bug since Dec 2016? I have same issues, I logged this issue, ansible/ansible#34851, but ansible closed it and referred my back to this issue. I have no clue how to move forward, is docker still working on this issue? Or is it an ansible issue?
Since this is one of the few that is still open, and since my issue on Ansible have been closed and pointed here, my details:
Ansible on Mac - the Controller, RPi3 with Stretch is the 'Managed Host', pip versions are:
$ pip freeze
| Mac - The Ansible Controller |
|---------------------------------------------- |
altgraph==0.10.2
ansible==2.4.2.0
asn1crypto==0.24.0
backports.ssl-match-hostname==3.5.0.1
bcrypt==3.1.4
bdist-mpkg==0.5.0
bonjour-py==0.3
cached-property==1.3.1
certifi==2017.11.5
cffi==1.11.4
chardet==3.0.4
cryptography==2.1.4
docopt==0.6.2
enum34==1.1.6
functools32==3.2.3.post2
idna==2.6
ipaddress==1.0.19
Jinja2==2.10
jsonschema==2.6.0
macholib==1.5.1
MarkupSafe==1.0
matplotlib==1.3.1
modulegraph==0.10.4
numpy==1.8.0rc1
paramiko==2.4.0
py2app==0.7.3
pyasn1==0.4.2
pycparser==2.18
pycrypto==2.6.1
PyNaCl==1.2.1
pyobjc-core==2.5.1
pyobjc-framework-Accounts==2.5.1
pyobjc-framework-AddressBook==2.5.1
pyobjc-framework-AppleScriptKit==2.5.1
pyobjc-framework-AppleScriptObjC==2.5.1
pyobjc-framework-Automator==2.5.1
pyobjc-framework-CFNetwork==2.5.1
pyobjc-framework-Cocoa==2.5.1
pyobjc-framework-Collaboration==2.5.1
pyobjc-framework-CoreData==2.5.1
pyobjc-framework-CoreLocation==2.5.1
pyobjc-framework-CoreText==2.5.1
pyobjc-framework-DictionaryServices==2.5.1
pyobjc-framework-EventKit==2.5.1
pyobjc-framework-ExceptionHandling==2.5.1
pyobjc-framework-FSEvents==2.5.1
pyobjc-framework-InputMethodKit==2.5.1
pyobjc-framework-InstallerPlugins==2.5.1
pyobjc-framework-InstantMessage==2.5.1
pyobjc-framework-LatentSemanticMapping==2.5.1
pyobjc-framework-LaunchServices==2.5.1
pyobjc-framework-Message==2.5.1
pyobjc-framework-OpenDirectory==2.5.1
pyobjc-framework-PreferencePanes==2.5.1
pyobjc-framework-PubSub==2.5.1
pyobjc-framework-QTKit==2.5.1
pyobjc-framework-Quartz==2.5.1
pyobjc-framework-ScreenSaver==2.5.1
pyobjc-framework-ScriptingBridge==2.5.1
pyobjc-framework-SearchKit==2.5.1
pyobjc-framework-ServiceManagement==2.5.1
pyobjc-framework-Social==2.5.1
pyobjc-framework-SyncServices==2.5.1
pyobjc-framework-SystemConfiguration==2.5.1
pyobjc-framework-WebKit==2.5.1
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
PyYAML==3.12
requests==2.18.4
scipy==0.13.0b1
six==1.4.1
urllib3==1.22
websocket-client==0.46.0
xattr==0.6.4
zope.interface==4.1.1
| RPi - the Managed Host. |
|--------------------------- |
backports.ssl-match-hostname==3.5.0.1
cached-property==1.3.1
certifi==2017.11.5
chardet==3.0.4
cryptography==1.7.1
docker==2.7.0
docker-pycreds==0.2.1
docopt==0.6.2
enum34==1.1.6
functools32==3.2.3.post2
idna==2.6
ipaddress==1.0.19
jsonschema==2.6.0
keyring==10.1
keyrings.alt==1.3
pyasn1==0.1.9
pycrypto==2.6.1
pygobject==3.22.0
pyxdg==0.25
PyYAML==3.12
requests==2.18.4
RPi.GPIO==0.6.3
SecretStorage==2.3.1
six==1.11.0
texttable==0.9.1
urllib3==1.22
websocket-client==0.46.0
docker on the Managed Host:
docker --version
Docker version 18.01.0-ce, build 03596f5
Ansible on the Mac Controller:
ansible --version
ansible 2.4.2.0
ansible python module location = /Library/Python/2.7/site-packages/ansible
python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
Python on the RPi
python --version
Python 2.7.13
With the above setup, docker_image works, but docker_container does not work.
This is after I removed docker-py from the RPi, cleaned up after .../site-packages/auth,
I also tried downgrading as per other suggestions:
pip uninstall docker docker-py ; pip install docker==2.0.1
But, sadly cannot get docker_container to work as well, still getting:
"Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"
But if I pip install docker-py on the 'managed host' or remove it and install pip install docker this does not work.
Where to from here?
According to https://github.com/ansible/ansible/issues/20492, for Failed to import docker-py for docker_container module, now also tried one of @jpriron 's suggestions, also not working:
pip uninstall docker
pip uninstall docker-py
pip uninstall docker-compose
pip install docker-compose==1.9.0
Just note, these suggestions dates back a year....
An further down, @jpiron suggests, unlike others, to uninstall docker and install docker-py again...
pip uninstall docker
pip install --ignore-installed docker-py
Sadly, ... still the same error.
Furtherdown, @Appleman suggest: (on the 'managed host')
pip uninstall docker
pip uninstall docker-py
pip install docker
But sadly, same error.
Furtherdown, @Appleman suggests to run the playbook with Python3, have no idea how to do this, will study it now...
And I solved it by run playbook under python3.
Furtherdown, @antoinetran clarifies, docker for python3, docker-py for python2.7, so back to the drawing board.
pip uninstall docker docker-py docker-compose
pip install docker-compose
Nope, still not working...., and versions are:
$ pip freeze | grep docker
docker==2.7.0
docker-compose==1.18.0
docker-pycreds==0.2.1
dockerpty==0.4.1
What now?????
check for a docker folder in your site packages after uninstalling everything, if its still there its the cause
part of this issue is partial metadata corruptio
Thank you Ronny, should I then just delete this docker folder - will that
be enough ?
I checked, pip uninstalled all docker* modules, none left in the folder
~/.local/lib/python2.7/site-packages
Dear all, I resolved my controller on Mac, Target on Pi with a test playbook.
I created a test bench from Mac to RPi with docker_login, docker_image, docker_container and docker_service. See it here:
https://github.com/IoTPlay/docker-iotplay-standards/blob/master/10_Test_docker-with-ansible.yml
All my tests pasts, after recreated a Pi from scratch, instructions in the above link as well. I used the standard pi user, and not a user I created myself through ansible. I will not have to go check what I missed out for this created user.
The instructions in the above link, installs the stock standard python programs on the TARGET (pi) machine, not using sudo.
$ sudo apt install python-pip
$ pip install docker-py
$ pip install docker-compose
Apologies for the 'noise' from me in this issue, maybe this can assist others.
J茅an.
@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
Ronny, your comment above is the most important statement of this -and ansible's multitude of issues logged. I wish they will update their software to not ask for the installation of docker-py, it cost me 3 weeks of investigations.
Thank you for your assistance.
@IoTPlay im glad my suggestion helped, please report this to ansible itself, perhaps linking this issue
note that there may be a unintended legacy requirement (changed apis between docker and docker-py)
in any case it would help if that mismatch was documented in a more discoverable fashion
Most helpful comment
You may need to uninstall the
docker-pypackage as it may be conflicting with the newdockerpackage.Let me know if it helps.