Skip to content

[BUG] docker_image.present erroring out: docker_image' __virtual__ returned False: 'docker.version' is not available. #62602

Closed

Description

@mohaldu

Description
Attempting to make use of docker_image.present fails.

Getting error message below:

          ID: create docker images
    Function: docker_image.present
      Result: False
     Comment: State 'docker_image.present' was not found in SLS 'prometheus/prometheus'
              Reason: 'docker_image' __virtual__ returned False: 'docker.version' is not available.
     Changes:

Setup
Running on ubuntu 20.04 server. Docker and docker python are installed like follows:

  • on-prem machine
  • VM (Virtualbox, KVM, etc. please specify)
  • VM running on a cloud service, please be explicit and add details
  • container (Kubernetes, Docker, containerd, etc. please specify)
  • or a combination, please be explicit
  • jails if it is FreeBSD

Steps to Reproduce the behavior

To install docker and pip.install the docker:

# Install docker

apt-transport-https:
  pkg.installed: []

docker_repository:
  pkgrepo.managed:
    - name: deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
    - file: /etc/apt/sources.list.d/docker.list
    - key_url: https://download.docker.com/linux/ubuntu/gpg
    - require:
      - pkg: apt-transport-https
    - require_in:
      - pkg: docker


docker:
  pkg.installed:
    - pkgs: [docker-ce, docker-compose-plugin]
  service.running:
    - name: docker
    - enable: true
    - reload: true
  pip.installed:
    - pkgs:
        - "docker"

restart_service:
  service.running:
    - name: salt-minion
    - enable: True
    - watch:
      - pip: docker

Then, running docker_image.present:

create docker images:
  docker_image.present:
    - build: /root/test_docker
    - tag: prom_tester
    - force: true

Expected behavior
The command works, instead we get errors

Screenshots
If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3005

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: 6.0.0
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.0
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.8.10 (default, Jun 22 2022, 20:18:18)
  python-gnupg: 0.4.5
        PyYAML: 5.3.1
         PyZMQ: 18.1.1
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2

System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.4.0-125-generic
        system: Linux
       version: Ubuntu 20.04 focal```
</details>

**Additional context**
I've tried restarting salt manually, tried reinstalling docker via pip, no success.

Activity

  1. added
    bug
    on Sep 1, 2022
  2. welcome commented on Sep 1, 2022

    @welcome

    Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
    Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

    There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
    If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

  3. OrangeDog commented on Sep 1, 2022

    @OrangeDog
    Contributor

    Possibly docker-py 6 has a breaking change not accounted for. If you install an earlier version does it then work?

  4. ccottam commented on Sep 1, 2022

    @ccottam

    I've hit the same issue, reverting the docker python module seems to offer a temporary fix
    salt '' pip.install docker==5.0.3

    so an issue with docker-py 6.0.0 seems likely

  5. added
    dependency
    on Sep 1, 2022
  6. Maxtaager commented on Sep 1, 2022

    @Maxtaager

    It is, i also was surprised by this: 6.0.0 moved the version function so downgrading to 5.x works.

  7. mohaldu commented on Sep 5, 2022

    @mohaldu
    Author

    Hi all, seems like downgrading to 5.x does work. I'm running into the same issue with salt's dockercompose, anyone know what version works? I've tried downgrading that a few versions now with no luck. Similar error with virtual returning false.

  8. thrashwerk commented on Oct 18, 2022

    @thrashwerk

    Same issue here. It works when downgrading to 5.0.3.

    The question is why doesn't the onedir installation have the correct (or any) version of docker included which is what it's supposed to do according to documenation or why don't the docs mention actually supported versions?

    https://docs.saltproject.io/en/latest/ref/states/all/salt.states.docker_container.html#module-salt.states.docker_container mentions that "all" docker versions are supported but that is simply not true and it would be wrong to assume that since it worked with 5.x it will work with 6.x or 7.x. That's why we there are these version numbers so you can expect breaking changes especially in major versions.

  9. dariosusman commented on Nov 1, 2022

    @dariosusman

    If tests are needed, please let me know as I've got a testing environment for this.

    I also refer to this: #54449

  10. max-arnold commented on Nov 3, 2022

    @max-arnold
    Contributor

    This issue was fixed in #62882 and can be closed

  11. fs30000 commented on Dec 17, 2022

    @fs30000

    Getting this error as well. Using salt-ssh - 3005.1 to have a container running on Centos 7 host.


          ID: nginx
    Function: docker_container.running
        Name: bitnami/nginx
      Result: False
     Comment: State 'docker_container.running' was not found in SLS 'nginx'
              Reason: 'docker_container' __virtual__ returned False: 'docker.version' is not available.
    

    Docker rpm version : docker-1.13.1-209.git7d71120.el7.centos.x86_64

  12. added this to the Sulphur v3006.0 milestone on Dec 17, 2022
  13. chateaulav commented on Jul 18, 2023

    @chateaulav

    Getting same error running as a state, and unable to gather correct dependency version tree for fix.
    System is Ubuntu 22.04, Salt 3005.1

    SLS Snippet:

    lancachenet_dns:
      docker_container.running:
        - name: lancache-dns
        - image: lancachenet/lancache-dns:latest
        - restart_policy: unless-stopped

    Output Snippet:

    ----------
    ID: lancachenet_monolith
    Function: docker_container.running
    Name: lancache
    Result: False
    Comment: State 'docker_container.running' was not found in SLS '/formulas/cache/configure'
    Reason: 'docker_container' __virtual__ returned False: 'docker.version' is not available.
    Changes:
    ----------                      

    docker versions on minion:

    # pip freeze
    docker==5.0.3
    docker-compose==1.29.2
    dockerpty==0.4.1
    
    root@cache:~# dpkg -l | grep docker
    ii  docker-compose                  1.29.2-1                                all          define and run multi-container Docker applications with YAML
    ii  docker.io                       20.10.21-0ubuntu1~22.04.3               amd64        Linux container runtime
    ii  python3-docker                  5.0.3-1                                 all          Python 3 wrapper to access docker.io's control socket
    ii  python3-dockerpty               0.4.1-2                                 all          Pseudo-tty handler for docker Python client (Python 3.x)

    Salt Version:
    Salt: 3005.1

    Dependency Versions:
    cffi: 1.14.6
    cherrypy: unknown
    dateutil: 2.8.1
    docker-py: Not Installed
    gitdb: Not Installed
    gitpython: Not Installed
    Jinja2: 3.1.0
    libgit2: 1.6.4
    M2Crypto: Not Installed
    Mako: Not Installed
    msgpack: 1.0.2
    msgpack-pure: Not Installed
    mysql-python: Not Installed
    pycparser: 2.21
    pycrypto: Not Installed
    pycryptodome: 3.9.8
    pygit2: 1.12.2
    Python: 3.9.16 (main, Jan 6 2023, 22:50:07)
    python-gnupg: 0.4.8
    PyYAML: 5.4.1
    PyZMQ: 23.2.0
    smmap: Not Installed
    timelib: 0.2.4
    Tornado: 4.5.3
    ZMQ: 4.3.4

    System Versions:
    dist: ubuntu 22.04 jammy
    locale: utf-8
    machine: x86_64
    release: 5.15.0-76-generic
    system: Linux
    version: Ubuntu 22.04 jammy

    Update

    did clean install on minion, and pinned docker 5.0.3 state was able to run successfully

    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# salt-pip freeze | grep docker
    docker==5.0.3
    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# pip freeze | grep docker
    docker==5.0.3
    docker-compose==1.29.2
    dockerpty==0.4.1
    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# dpkg -l | grep docker
    ii  docker                          1.5-2                                   all          transitional package
    ii  docker-compose                  1.29.2-1                                all          define and run multi-container Docker applications with YAML
    ii  docker.io                       20.10.21-0ubuntu1~22.04.3               amd64        Linux container runtime
    ii  python3-docker                  5.0.3-1                                 all          Python 3 wrapper to access docker.io's control socket
    ii  python3-dockerpty               0.4.1-2                                 all          Pseudo-tty handler for docker Python client (Python 3.x)
    ii  wmdocker                        1.5-2                                   amd64        System tray for KDE3/GNOME2 docklet applications
  14. zyxep commented on Jul 18, 2023

    @zyxep

    Getting same error running as a state, and unable to gather correct dependency version tree for fix. System is Ubuntu 22.04, Salt 3005.1

    SLS Snippet:

    lancachenet_dns:
      docker_container.running:
        - name: lancache-dns
        - image: lancachenet/lancache-dns:latest
        - restart_policy: unless-stopped

    Output Snippet:

    ----------
    ID: lancachenet_monolith
    Function: docker_container.running
    Name: lancache
    Result: False
    Comment: State 'docker_container.running' was not found in SLS '/formulas/cache/configure'
    Reason: 'docker_container' __virtual__ returned False: 'docker.version' is not available.
    Changes:
    ----------                      

    docker versions on minion:

    # pip freeze
    docker==5.0.3
    docker-compose==1.29.2
    dockerpty==0.4.1
    
    root@cache:~# dpkg -l | grep docker
    ii  docker-compose                  1.29.2-1                                all          define and run multi-container Docker applications with YAML
    ii  docker.io                       20.10.21-0ubuntu1~22.04.3               amd64        Linux container runtime
    ii  python3-docker                  5.0.3-1                                 all          Python 3 wrapper to access docker.io's control socket
    ii  python3-dockerpty               0.4.1-2                                 all          Pseudo-tty handler for docker Python client (Python 3.x)

    Salt Version: Salt: 3005.1

    Dependency Versions: cffi: 1.14.6 cherrypy: unknown dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 3.1.0 libgit2: 1.6.4 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.9.8 pygit2: 1.12.2 Python: 3.9.16 (main, Jan 6 2023, 22:50:07) python-gnupg: 0.4.8 PyYAML: 5.4.1 PyZMQ: 23.2.0 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4

    System Versions: dist: ubuntu 22.04 jammy locale: utf-8 machine: x86_64 release: 5.15.0-76-generic system: Linux version: Ubuntu 22.04 jammy

    Update

    did clean install on minion, and pinned docker 5.0.3 state was able to run successfully

    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# salt-pip freeze | grep docker
    docker==5.0.3
    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# pip freeze | grep docker
    docker==5.0.3
    docker-compose==1.29.2
    dockerpty==0.4.1
    root@cache-d8ffaef6-022f-5320-8a6e-844dc4fecc4a:~# dpkg -l | grep docker
    ii  docker                          1.5-2                                   all          transitional package
    ii  docker-compose                  1.29.2-1                                all          define and run multi-container Docker applications with YAML
    ii  docker.io                       20.10.21-0ubuntu1~22.04.3               amd64        Linux container runtime
    ii  python3-docker                  5.0.3-1                                 all          Python 3 wrapper to access docker.io's control socket
    ii  python3-dockerpty               0.4.1-2                                 all          Pseudo-tty handler for docker Python client (Python 3.x)
    ii  wmdocker                        1.5-2                                   amd64        System tray for KDE3/GNOME2 docklet applications

    they do write the fix was merged into 3006.

  15. stigok commented on Mar 22, 2024

    @stigok

    For those who are stuck on Salt version 3005.x for some reason, a work-around is applying the same kind of patch as Salt has done themselves, just in the docker-py package itself.

    On the servers where you have this problem:

    1. Upgrade docker-py to the version you'd want. Probably the latest one. # salt-pip install -U docker
    2. Patch the init-file of the docker-py module at /opt/saltstack/salt/pypath/lib/python3.9/site-packages/docker/__init__.py, by adding the following line:
    from ._version import version_tuple as version_info
    1. This command should work properly now: # salt-call docker.version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdependencyneeds-triage

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions