# How would I convert this docker using the ansible docker module?

**URL:** <https://forum.ansible.com/t/how-would-i-convert-this-docker-using-the-ansible-docker-module/16504>\
**Category:** Ansible Project\
**Created:** [October 14, 2014, 4:17pm UTC](https://forum.ansible.com/t/how-would-i-convert-this-docker-using-the-ansible-docker-module/16504 "2014-10-14T16:17:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Roebuck](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@Chris\_Roebuck](https://forum.ansible.com/u/Chris_Roebuck)\
**Post date:** [October 14, 2014, 4:17pm UTC](https://forum.ansible.com/t/how-would-i-convert-this-docker-using-the-ansible-docker-module/16504/1 "2014-10-14T16:17:17Z")

</div>

Command is from the google cAdvisor docker repo ([https://github.com/google/cadvisor](https://github.com/google/cadvisor)):

```auto
sudo docker run \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --publish=8080:8080 \
  --detach=true \
  --name=cadvisor \
  google/cadvisor:latest

```

I tried the following:

```auto
- name: 'Start cAdvisor'
  hosts: live
  sudo: yes
  gather_facts: no
  vars:
    theVolumes: 
      - '/:/rootfs:ro'
      - '/var/run:/var/run:rw'
      - '/sys:/sys:ro'
      - '/var/lib/docker/:/var/lib/docker:ro'
  tasks:
    - name: "run cAdvisor docker image"
      docker: 
        image: google/cadvisor:latest 
        name: cadvisor 
        volumes: {{ theVolumes }}
        ports: 8080:8080
        state: running

```

and

```auto
- name: 'Start cAdvisor'
  hosts: live
  sudo: yes
  gather_facts: no
  tasks:
    - name: "run cAdvisor docker image"
      docker: 
        image: google/cadvisor:latest 
        name: cadvisor 
        volumes: '/:/rootfs:ro,/var/run:/var/run:rw,/sys:/sys:ro,/var/lib/docker/:/var/lib/docker:ro'
        ports: 8080:8080
        state: running

```

Both methods get the same error from Docker:

```auto
TASK: [run cAdvisor docker image] *********************************************
failed: [...] => {"changed": false, "failed": true}
msg: Docker API error: Cannot start container d36a56b68ac91d08ca804a5ee8a230796ed590e11576a0204b5f056d3c74fded: Invalid volume specification: /var/lib/docker/:{'bind': '/var/lib/docker', 'ro': True}

```

---

<div class="post-metadata">

**Author:** ![Mathieu\_Guillaume](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mathieu\_Guillaume](https://forum.ansible.com/u/Mathieu_Guillaume)\
**Post date:** [October 16, 2014, 4:57pm UTC](https://forum.ansible.com/t/how-would-i-convert-this-docker-using-the-ansible-docker-module/16504/2 "2014-10-16T16:57:44Z")

</div>

I’ve tried the second version locally, it works fine for me (well, I’ve been testing with the ubuntu:trusty image but that doesn’t change the syntax).  
The first one gives me a syntax error, but replacing the volumes line with: volumes: “{{theVolumes|default()|join(‘,’)}}” fixes it.

What versions of ansible/docker/docker-py are you using? Have you tried with the latest releases?
