Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to deploy container #230

Closed
alirizv opened this issue Oct 11, 2023 · 8 comments
Closed

Unable to deploy container #230

alirizv opened this issue Oct 11, 2023 · 8 comments
Assignees

Comments

@alirizv
Copy link

alirizv commented Oct 11, 2023

Hello, thank you so much for this code. The rootless docker installs fine and docker is available to the dedicated user. I can run docker ps and see there are no containers. However, when I try to deploy the container using Ansible. I am getting the following error:

FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on host machine's Python /usr/bin/python3. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via pip install dockerorpip install docker-py (Python 2.6). The error was: No module named 'requests'"}

I have logged into dedicated user and checked version of Python, and everything checks out. Any help would be much appreciated.

@konstruktoid
Copy link
Owner

konstruktoid commented Oct 11, 2023

Hi! And thanks for using the role :)

As the Docker user, can you get the Python version and the output of python3 -m pip list | grep docker?

What distribution are you running by the way?

@alirizv
Copy link
Author

alirizv commented Oct 11, 2023

As the Docker user, can you get the Python version and the output of python3 -m pip list | grep docker?

What distribution are you running by the way?

Operating System: Red Hat Enterprise Linux 8.8 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
Kernel: Linux 4.18.0-425.10.1.el8_7.x86_64

you command did not work for me so I had to run a variation, it does not seem to be working correctly, but do not see docker in the list

python3 -m pip list --format=columns grep docker
Package Version


Babel 2.5.1
bcc 0.25.0
cffi 1.11.5
chardet 3.0.4
cloud-init 22.1
configobj 5.0.6
configshell-fb 1.1.28
cryptography 3.2.1
dbus-python 1.2.4
decorator 4.2.1
dnspython 1.15.0
ethtool 0.14
file-magic 0.3.0
gpg 1.13.1
html5lib 0.999999999
iniparse 0.4
iotop 0.6
isc 2.0
Jinja2 2.10.1
jsonpatch 1.21
jsonpointer 1.10
jsonschema 2.6.0
kmod 0.1
libcomps 0.1.18
lxml 4.2.3
MarkupSafe 0.23
netaddr 0.7.19
netifaces 0.10.6
nftables 0.1
oauthlib 2.1.0
perf 0.1
pexpect 4.3.1
pip 9.0.3
ply 3.9
prettytable 0.7.2
psutil 5.4.3
psycopg2 2.7.5
ptyprocess 0.5.2
pyasn1 0.3.7
pycairo 1.16.3
pycparser 2.14
pydbus 0.6.0
pygobject 3.28.3
pyinotify 0.9.6
PyJWT 1.6.1
pyodbc 4.0.0-unsupported
pyparsing 2.1.10
pyserial 3.1.1
PySocks 1.6.8
python-augeas 0.5.0
python-dateutil 2.6.1
python-dmidecode 3.12.2
python-linux-procfs 0.7.0
pytz 2017.2
pyudev 0.21.0
PyYAML 3.12
rpm 4.14.3
rtslib-fb 2.1.75
selinux 2.9
sepolicy 1.1
setools 4.3.0
setroubleshoot 1.1
setuptools 39.2.0
six 1.11.0
slip 0.6.4
slip.dbus 0.6.4
sos 4.6.0
SSSDConfig 2.8.2
subscription-manager 1.28.36
syspurpose 1.28.36
systemd-python 234
targetcli-fb 2.1.53
urwid 1.3.1
WALinuxAgent 2.7.0.6
webencodings 0.5.1

@alirizv
Copy link
Author

alirizv commented Oct 11, 2023

Docker 5.0.3 is available if I run the same command under root. Sorry I am still learning this and may not know the obvious answer. This is the Ansible command I use to install docker python. However, it is not being made available to the dedicated dockeruser:

  • name: Install python docker, needed to deploy container
    ansible.builtin.pip:
    name: docker
    umask: "0022"
    executable: /usr/local/bin/pip3
    state: forcereinstall

@konstruktoid
Copy link
Owner

It should be available anyway.

What happens it you use

- name: Register Docker user info
  become: true
  ansible.builtin.user:
    name: "{{ docker_user }}"
  check_mode: true
  register: docker_user_info

- name: Example container block
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ docker_user_info.uid }}"
    PATH: "{{ docker_user_info.home }}/bin:{{ ansible_env.PATH }}"
    DOCKER_HOST: "unix:///run/user/{{ docker_user_info.uid }}/docker.sock"
  block:
    - name: Nginx container
      become: true
      become_user: "{{ docker_user }}"
      community.docker.docker_container:
        name: nginx
        image: konstruktoid/nginx
        state: started
        cap_drop: all
        capabilities:
          - chown
          - dac_override
          - net_bind_service
          - setgid
          - setuid
        pull: true
        hostname: "{{ ansible_nodename }}"
        container_default_behavior: compatibility

@alirizv
Copy link
Author

alirizv commented Oct 12, 2023

- name: Register Docker user info
  become: true
  ansible.builtin.user:
    name: "{{ docker_user }}"
  check_mode: true
  register: docker_user_info

- name: Example container block
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ docker_user_info.uid }}"
    PATH: "{{ docker_user_info.home }}/bin:{{ ansible_env.PATH }}"
    DOCKER_HOST: "unix:///run/user/{{ docker_user_info.uid }}/docker.sock"
  block:
    - name: Nginx container
      become: true
      become_user: "{{ docker_user }}"
      community.docker.docker_container:
        name: nginx
        image: konstruktoid/nginx
        state: started
        cap_drop: all
        capabilities:
          - chown
          - dac_override
          - net_bind_service
          - setgid
          - setuid
        pull: true
        hostname: "{{ ansible_nodename }}"
        container_default_behavior: compatibility

I am getting following error:
fatal: [10.145.20.46]: FAILED! => {"reason": "couldn't resolve module/action 'community.docker.docker_container'. This often indicates a misspelling, missing collection, or incorrect module path.\n\nThe error appears to be in '/home/syed.rizvi/gitlab-runner-docker-executor/src/roles/nginix/tasks/install/main.yml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n block:\n - name: Nginx container\n ^ here\n"}

When I look the error up, its the same thing: Docker Python must be installed. My problem is that even though Docker Python 5.0.3 is installed under root scope. It is not being made available to the dedicated dockeruser.

@konstruktoid
Copy link
Owner

couldn't resolve module/action 'community.docker.docker_container (https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html), you'll most likely need to run ansible-galaxy install -r requirements.yml in your GitLab runner

@alirizv
Copy link
Author

alirizv commented Oct 16, 2023

couldn't resolve module/action 'community.docker.docker_container (https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html), you'll most likely need to run ansible-galaxy install -r requirements.yml in your GitLab runn

@alirizv alirizv closed this as completed Oct 16, 2023
@alirizv alirizv reopened this Oct 16, 2023
@alirizv
Copy link
Author

alirizv commented Oct 20, 2023

@konstruktoid thank you for the help. The issue was resolved by installing PIP docker using the shell play on my Ansible playbook as follows:

  • name: check if pip docker is installed
    ansible.builtin.shell: pip list | grep docker
    register: docker_installed
    ignore_errors: True
    check_mode: False
    changed_when: False

  • name: Install pip docker, needed to deploy container
    become_user: "{{ docker_user }}"
    ansible.builtin.shell: python3 -m pip install --user docker
    register: output_py_ver
    when: docker_installed.rc != 0

@alirizv alirizv closed this as completed Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants