Centos7 docker-py doesn't seem to be installed

血红的双手。 提交于 2020-01-01 08:25:09

问题


I installed Centos7 minimal and then: ansible, docker, pip and using pip I installed docker-py.

Versions:
- Docker version 1.6.0, build 8aae715/1.6.0
- ansible 1.9.1
- docker_py-1.2.2

Trying to run a playbook, for example

- name: redis container
  docker:
    name: myredis
    image: redis
    state: started

i get msg: docker-py doesn't seem to be installed, but is required for the Ansible Docker module.

I can't see the problem. Is it the CentOS, docker and ansible version?

PS: I disabled the firewalld and SELinux

Any ideas? Thanks


回答1:


I found a couple problems with the docker-py module. After I worked through them I ended up with this:

  - name: Docker-PY
    pip:
      name: "{{ item }}"
    with_items:
    - six==1.4
    - docker-py==1.1.0

First, I ran into your problem. The solution is to explicitly set the most recent version of six as described here: https://github.com/docker/docker-py/issues/344.

After that, I ran into an issue (you might run into it too) with a bug in the docker-py 1.2.2 version. The workaround is to specify an older version as described here: https://github.com/ansible/ansible-modules-core/issues/1227. Do a pip uninstall docker-py to get rid of the newer version.

If you aren't using ansible to install these then do this:

[sudo] pip uninstall docker-py
[sudo] pip install six==1.4
[sudo] pip install docker-py==1.1.0



回答2:


If you're working on CentOS7 or similar, you may not want to install unpackaged code via pip. In which case, it's good to know that the Extras channel has a package python-docker-py. I had this problem, installed that package, and was off to the races.




回答3:


tl;dr;

check file permissions and make sure your user can read the python module in /usr/lib/python2.7/site-packages

Context

I recently went to this is issue but it was a permission problem.

Note that I used docker 1.9.1, ansible 2.0.1.0 and redhat 7.2.

I installed docker-py with ansible (this might not be your case).

I did it with this role:

- name: install docker-py with pip
  become: true
  pip: state=present name='{{ item }}'
  with_item:
    - docker-py==1.2.3
    - six==1.10.0

Problem

When sudoing, ansible may install docker-py with default umask 0077. As a result, no user, except root, will be able to read docker-py module files.

Your playbook will result with the docker-py doesn't seem to be installed, but is required for the Ansible Docker module error.

Notice the differences between:

  • sudo pip install docker-py => /usr/lib/python2.7/site-packages/docker is in mode 0700
  • sudo su then pip install docker-py => /usr/lib/python2.7/site-packages/docker is in mode 0755

Fix

This will be fixable with ansible 2.1 by passing the umask=0022 parameter to the pip module (see https://github.com/ansible/ansible-modules-core/commit/4b46200477216dbcc54611d1c3e6f0cc83757aaf).

For now I fixed it by removing all packages installed in mode 0700:

pip uninstall -y six docker-py websocket_client

Then reinstalling them by hand:

sudo su
# now umask is 0022
pip install six==1.10.0 docker-py==1.2.3



回答4:


I ran into a variation of this issue recently. It wasn't due to my using sudo to install the module, but the other way around.

For whatever reason I opted to install docker using pip's --user flag and then had the unfortunate "idea" to use the -b or --become option.

This resulted in the "obviously" installed docker module being unavailable to the elevated Ansible instance running my playbook. Sharing in case someone has "one of those days" and stumbles across this later on. Hope it helps you as I paid for this reminder with a good bit of "stupid tax", hopefully enough for the both of us. :)



来源:https://stackoverflow.com/questions/30350881/centos7-docker-py-doesnt-seem-to-be-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!