Skip to content

dockerio state, mount volumes dosn't work #14089

Closed

Description

@jacksoncage

I'm using dockerio salt state to startup docker containers on a salt minion. Trying to mount volumes into my container is failing. Container is starting but volumes are mounted to the right places.

Aiming for this

sudo docker run \
  --volume=/var/run:/var/run:rw \
  --volume=/sys/fs/cgroup/:/sys/fs/cgroup:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --publish=8080:8080 \
  --detach=true \
  google/cadvisor

cadvisor sls file

cadvisor-image:
   docker.pulled:
     - name: google/cadvisor
     - tag: latest
     - require_in: cadvisor-container
     - force: True

cadvisor-container:
   docker.installed:
     - name: cadvisor
     - hostname: cadvisor
     - image: google/cadvisor
     - ports:
       - "8080/tcp"
     - volumes:
       - /var/run:/var/run
       - /sys/fs/cgroup:/sys/fs/cgroup
       - /var/lib/docker:/var/lib/docker
     - require_in: cadvisor

cadvisor:
   docker.running:
     - container: cadvisor
     - port_bindings:
            "8080/tcp":
                HostIp: ""
                HostPort: "8080"
     - binds:
       /var/run:
         bind: /var/run
         rw: true
       /sys/fs/cgroup:
         bind: /sys/fs/cgroup
       /var/lib/docker:
         bind: /var/lib/docker

According to the dockerio.py /var/run:/var/run should work.

docker inspect cadvisor

    "Volumes": {
        "/sys/fs/cgroup": "/data/docker/var/lib/docker/vfs/dir/4b73afb95950512f14b1756234d99301cd1092bab090ed6b8d346a33f07592d4",
        "/var/lib/docker": "/data/docker/var/lib/docker/vfs/dir/d26ca697e1bcc0f33ce2e4da48e7bb063c7820513850aede726e683a6b91cadd",
        "/var/run": "/data/docker/var/lib/docker/vfs/dir/a78769e20861055f0bb3c85b024a325c61b57451520c8c918b9b73b7586c655d"
    },
    "VolumesRW": {
        "/sys/fs/cgroup": true,
        "/var/lib/docker": true,
        "/var/run": true
    }

Should look like this if volumes where right

    "Volumes": {
        "/sys/fs/cgroup": "/sys/fs/cgroup",
        "/var/lib/docker": "/var/lib/docker",
        "/var/run": "/run"
    },
    "VolumesRW": {
        "/sys/fs/cgroup": false,
        "/var/lib/docker": false,
        "/var/run": true
    }

Versions

love@master:~$ cat /etc/issue
Ubuntu 12.04.1 LTS \n \l

love@master:~$ salt server01 cmd.run "docker version"
server01:
    Client version: 1.1.1
    Client API version: 1.13
    Go version (client): go1.2.1
    Git commit (client): bd609d2
    Server version: 1.1.1
    Server API version: 1.13
    Go version (server): go1.2.1
    Git commit (server): bd609d2

love@master:~$ salt server01 cmd.run "salt-minion --version"
server01:
    salt-minion 2014.1.7

love@master:~$ salt --version
salt 2014.1.7

Activity

  1. pidah commented on Jul 10, 2014

    @pidah

    +1 This doesn't work for me either on this version -
    salt --versions
    Salt: 2014.1.6
    Python: 2.7.3 (default, Feb 27 2014, 19:58:35)
    Jinja2: 2.7.3
    M2Crypto: 0.21.1
    msgpack-python: 0.4.2
    msgpack-pure: Not Installed
    pycrypto: 2.4.1
    PyYAML: 3.10
    PyZMQ: 14.3.1
    ZMQ: 4.0.4

  2. basepi commented on Jul 11, 2014

    @basepi
    Contributor

    Would one of you mind testing on the develop branch? The Docker support is still very new and is still evolving fairly rapidly, so there's a chance this has already been fixed.

  3. added this to the Approved milestone on Jul 11, 2014
  4. oba11 commented on Aug 16, 2014

    @oba11
    Contributor

    Tested the one in develop branch but doesnt seem to work either

  5. mikea commented on Aug 18, 2014

    @mikea

    I'm seeing this as well

  6. jacksoncage commented on Aug 18, 2014

    @jacksoncage
    Author

    Can confirm not working in develop as well.

  7. mzdaniel commented on Aug 20, 2014

    @mzdaniel
    Contributor

    Is it a salt design decision to define volume mapping in docker.installed as it were docker run -v, instead of letting docker.running deal with the actual volume bind mapping?

    docker.installed calls docker-py create_container. According to https://github.com/docker/docker-py#using-volumes, volumes in create_container are generically declared which makes sense as they are just references at creation time.

    Currently, volume binding will work with no salt code modification if in this exaple we make cadvisor -binds read as (notice the / at the end of the path):

    - binds:
       /var/run/:
         bind: /var/run
       /sys/fs/cgroup/:
         bind: /sys/fs/cgroup
         ro: true
       /var/lib/docker/:
         bind: /var/lib/docker
         ro: true
    

    Here are the software versions I used to test:

    salt-call cmd.run "docker version"
    local:
    Client version: 1.1.2
    Client API version: 1.13
    Go version (client): go1.3
    Git commit (client): d84a070
    Server version: 1.1.0
    Server API version: 1.13
    Go version (server): go1.3
    Git commit (server): 79812000

    salt-call --version
    salt-call 2014.7.0rc1-867-g5ba675f (Helium)

    salt-call cmd.run "python -c 'import docker; print(docker.version)'"
    local:
    0.4.0

  8. mzdaniel commented on Oct 16, 2014

    @mzdaniel
    Contributor

    Hi @jacksoncage, @pidah , @basepi , @oba11, @mikea.
    Is this still considered an issue given, for example, the slight syntactic clarification above?

  9. immunda commented on Oct 17, 2014

    @immunda
    Contributor

    The above is working fine for me.

    I really think the Salt docs need to be updated to reflect this though.

  10. cachedout commented on Oct 17, 2014

    @cachedout
    Contributor

    Hi @immunda.

    Would you be willing to submit a PR to the docs to correct them as you see fit? We'd love to see your suggestions, if you have a bit of free time.

  11. immunda commented on Oct 17, 2014

    @immunda
    Contributor

    Sure, I'll try and grab some time early next week (-:

  12. cachedout commented on Oct 17, 2014

    @cachedout
    Contributor

    Awesome! We look forward to your contributions.

  13. mzdaniel commented on Oct 17, 2014

    @mzdaniel
    Contributor

    Thank you for checking Phil

  14. 10 remaining items

  15. basepi commented on May 12, 2015

    @basepi
    Contributor

    Hint: use script_args in your map to pass bootstrap arguments (to control which version is installed)

    ubuntu-14.04:
      - basepi_minion_master:
          make_master: True
          minion:
            local_master: True
          script_args: git v2015.5.0
      - basepi_minion1:
          minion:
            local_master: True
          script_args: git v2015.5.0
    debian-7:
      - basepi_minion2:
          minion:
            local_master: True
          script_args: git v2015.5.0
    cent-6.5:
      - basepi_minion3:
          minion:
            local_master: True
          script_args: git v2015.5.0
    

    You can also pass in --script-args='git v2015.5.0' to the salt-cloud command.

  16. tkent-xetus commented on May 12, 2015

    @tkent-xetus

    @basepi thanks!

    I ended up using script_args: 'stable XXXX' after checking out the bootstrap-salt.sh source. Since we use ubuntu systems, that made sense to me.

    There's no special reason you suggested git instead, right? As in, I'm not going to regret using stable later, am I :-)

  17. basepi commented on May 12, 2015

    @basepi
    Contributor

    Nope, should be fine! I just tend to use git so I can target exact git tags. =)

  18. tkent-xetus commented on May 16, 2015

    @tkent-xetus

    @basepi ha! You were wrong, I do regret using script_args: 'stable XXXX' :-P.

    It turns out that the feature to specify the package version for 'stable' bootstraps is not included with the boostrap-salt script in 2015.5.0. I happened to be testing locally with a newer version and didn't notice. I've swapped to using the git args and it works great.

  19. basepi commented on May 18, 2015

    @basepi
    Contributor

    Well, I'm glad you got it figured out! =D

  20. added
    severity-medium
    P2
    Platform
    and removed
    severity-low
    on Jul 14, 2015
  21. discordianfish commented on Jul 21, 2015

    @discordianfish

    I'm running 2015.5.2 and using 'volumes' and I tried both:

      docker.running:
        - container: prometheus-server
        - image: prom/prometheus:latest
        - volumes:
          - /etc/prometheus:/etc/prometheus
        - ports:
            "9090/tcp":
                HostIp: ""
                HostPort: "9090"
    

    as well as:

    prometheus_server:
      docker.running:
        - container: prometheus-server
        - image: prom/prometheus:latest
        - volumes:
          - /etc/prometheus:
            bind: /etc/prometheus
            ro: True
        - ports:
            "9090/tcp":
                HostIp: ""
                HostPort: "9090"
    

    But neither worked. The volume doesn't get bind-mounted.

  22. immunda commented on Jul 21, 2015

    @immunda
    Contributor

    @discordianfish This is from a working state with docker-py==1.2.2 and Salt 2015.5, let me know if it helps.

    {{ name }}-image:
      docker.pulled:
        - name: {{ image }}
        - tag: latest
        - require_in: {{ name }}-container
    
    {{ name }}-container:
      docker.installed:
        - name: {{ name }}
        - hostname: {{ name }}
        - volumes:
          - /projects/: /projects/
        - image: {{ image }}
        - require_in: {{ name }}
    
    {{ name }}:
      docker.running:
        - image: {{ image }}
        - container: {{ name }}
        - volumes:
            /projects/:
              bind: /projects/
        - ports:
            "9090/tcp":
                HostIp: ""
                HostPort: "9090"
        - restart_policy:
            MaximumRetryCount: 0
            Name: always
        - links:
            consul: consul
    
  23. stale commented on Dec 4, 2017

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

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

    P2PlatformState-Modulebugseverity-mediumstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions