Hi all,
I tried to use the volumes option and nothing seems to work for me.
I want to mount 2 directories ~/dockerstorage/model and ~/repo/ops/ansible to the container and I used either of these commands and nothing worked.
docker: image:5000=registry.my.com/steven/centos65_prod_ready:v1 docker_url=tcp://{{ ansible_default_ipv4.address }}:7777 publish_all_ports=True state=running volumes=/home/kafka/models:{{ myhome.stdout }}/dockerstorage/models:rw,/usr/local/src/ansible:{{ myhome.stdout }}/repo/ops/ansible:ro
docker: image:5000=registry.my.com/steven/centos65_prod_ready:v1 docker_url=tcp://{{ ansible_default_ipv4.address }}:7777 publish_all_ports=True state=running volumes={{ myhome.stdout }}/dockerstorage/models:/home/kafka/models:rw,{{ myhome.stdout }}/repo/ops/ansible:/usr/local/src/ansible:ro
I sshed into the containers and the mounted points in either case were all empty.
I ran using docker directly and it worked for me:
docker run -d -P -v /home/steven/dockerstorage/models:/home/kafka/models:rw -v /home/steven/repo/ops/ansible:/usr/local/src/ansible:ro registry.my.com:5000/steven/centos65_prod_ready:v1
Please let me know what is the right ways to use “volumes” for docker. >From the comments in the docker module, it appears to me that the /mnt:/tmp is in reversed orders from those of the docker command line because of the case when we just want to create a volume such as /mnt and there is no equivalent mounted point from the host. I think that this is confusing and users have to read the codes to find out.
Thanks,
Steven.
[root@sc2-dock1 cloud]# pwd
/usr/local/ansible/library/cloud
class DockerManager:
counters = {‘created’:0, ‘started’:0, ‘stopped’:0, ‘killed’:0, ‘removed’:0, ‘restarted’:0, ‘pull’:0}
def init(self, module):
self.module = module
self.binds = None
self.volumes = None
if self.module.params.get(‘volumes’):
self.binds = {}
self.volumes = {}
vols = self.module.params.get(‘volumes’)
for vol in vols:
parts = vol.split(“:”)
host mount (e.g. /mnt:/tmp, bind mounts host’s /tmp to /mnt in the container)
if len(parts) == 2:
self.volumes[parts[1]] = {}
self.binds[parts[0]] = parts[1]
docker mount (e.g. /www, mounts a docker volume /www on the container at the same location)
else:
self.volumes[parts[0]] = {}