salt icon indicating copy to clipboard operation
salt copied to clipboard

[state.dockerio] AttributeError: 'list' object has no attribute 'items'

Open MarkusMuellerAU opened this issue 12 years ago • 8 comments

Getting the following error running state.highstate

----------
          ID: postgresql_service
    Function: docker.running
      Result: False
     Comment: Container 'postgresql' cannot be started
              Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/modules/dockerio.py", line 910, in start
                  privileged=privileged)
                File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 717, in start
                  '{0}:{1}'.format(host, dest) for host, dest in binds.items()
              AttributeError: 'list' object has no attribute 'items'
     Changes:
----------

I am trying to create a container with binds/local mounts the following way:

postgresql_container:
    docker.installed:
        - name: postgresql
        - hostname: postgresql.internal
        - image: postgresql:9.3
        - volumes:
          - /var/log/postgresql
          - /var/lib/postgresql

postgresql_service:
    docker.running:
        - container: postgresql
        - port_bindings:
            "5432/tcp":
                HostIp: ""
                HostPort: "9000"
        - binds:
          - /userdata/shared_service/postgresql1/log: /var/log/postgresql
          - /userdata/shared_service/postgresql1/data: /var/lib/postgresql
        - require:
            - file: /userdata/shared_service/postgresql1/data
            - file: /userdata/shared_service/postgresql1/log


This is the --versions-report on my master:

          Salt: 2014.1.1
         Python: 2.7.3 (default, Feb 27 2014, 19:58:35)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.4.1
         PyYAML: 3.10
          PyZMQ: 13.0.0
            ZMQ: 3.2.2

On the minion 2014.1.0 is running on Ubuntu 13.10, but I didn't find a hint in the release notes that this issue would be fixed in 2014.1.1 either.

MarkusMuellerAU avatar Apr 09 '14 11:04 MarkusMuellerAU

Hrm, I'm not sure what's going on here. We'll investigate.

basepi avatar Apr 14 '14 18:04 basepi

You have incorrect syntax in your binds argument to the docker.running state. You're defining this value as a list, when it should be a dictionary like the port_bindings argument.

I'll fix the traceback and try to provide a better error message, but if you replace the leading dashes in the "binds" argument with spaces, this should get rid of the error.

terminalmage avatar Apr 14 '14 20:04 terminalmage

Also, keep in mind that you need to double-indent nested dictionaries due to weirdness with PyYAML. This behavior is explained better here.

Note that you have the correct formatting in port_bindings, you just need to format binds in the same way.

terminalmage avatar Apr 14 '14 20:04 terminalmage

Hi, thank you both for your reply. Changing the binds to:

        - binds: 
            "/userdata/sharedservice/postgresql1/log": "/var/log/postgresql"

fixed the issue, the container is now starting successfully. My syntax was taken from the saltstack documentation at http://docs.saltstack.com/en/latest/ref/states/all/salt.states.dockerio.html#salt.states.dockerio.running

binds like -v of docker run command

- binds:
    - /var/log/service: /var/log/service

I have changed the documentation accordingly and created pull request #11988

MarkusMuellerAU avatar Apr 14 '14 20:04 MarkusMuellerAU

Oh wow, thanks. I'll fix that.

terminalmage avatar Apr 14 '14 22:04 terminalmage

OK, I updated my pull request with a fix for that documentation issue. Thanks for mentioning that!

terminalmage avatar Apr 14 '14 22:04 terminalmage

Pleasure, glad I could help.

MarkusMuellerAU avatar Apr 14 '14 22:04 MarkusMuellerAU

Great, I'll close this then.

terminalmage avatar Apr 15 '14 18:04 terminalmage