mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
Fix bind-volumes on docker >= 1.4.0
If bind-volumes are submitted to docker >= 1.4.0 with the volumes set in addition to the binds, docker will create a regular volume and not bind-mount the specified path.
This commit is contained in:
parent
fa463fb1b7
commit
50fe57fff3
1 changed files with 15 additions and 13 deletions
|
@ -548,20 +548,22 @@ class DockerManager(object):
|
||||||
vols = self.module.params.get('volumes')
|
vols = self.module.params.get('volumes')
|
||||||
for vol in vols:
|
for vol in vols:
|
||||||
parts = vol.split(":")
|
parts = vol.split(":")
|
||||||
# host mount (e.g. /mnt:/tmp, bind mounts host's /tmp to /mnt in the container)
|
# regular volume
|
||||||
if len(parts) == 2:
|
if len(parts) == 1:
|
||||||
self.volumes[parts[1]] = {}
|
|
||||||
self.binds[parts[0]] = parts[1]
|
|
||||||
# with bind mode
|
|
||||||
elif len(parts) == 3:
|
|
||||||
if parts[2] not in ['ro', 'rw']:
|
|
||||||
self.module.fail_json(msg='bind mode needs to either be "ro" or "rw"')
|
|
||||||
ro = parts[2] == 'ro'
|
|
||||||
self.volumes[parts[1]] = {}
|
|
||||||
self.binds[parts[0]] = {'bind': parts[1], 'ro': ro}
|
|
||||||
# docker mount (e.g. /www, mounts a docker volume /www on the container at the same location)
|
|
||||||
else:
|
|
||||||
self.volumes[parts[0]] = {}
|
self.volumes[parts[0]] = {}
|
||||||
|
# host mount (e.g. /mnt:/tmp, bind mounts host's /tmp to /mnt in the container)
|
||||||
|
elif 2 <= len(parts) <= 3:
|
||||||
|
# default to read-write
|
||||||
|
ro = False
|
||||||
|
# with supplied bind mode
|
||||||
|
if len(parts) == 3:
|
||||||
|
if parts[2] not in ['ro', 'rw']:
|
||||||
|
self.module.fail_json(msg='bind mode needs to either be "ro" or "rw"')
|
||||||
|
else:
|
||||||
|
ro = parts[2] == 'ro'
|
||||||
|
self.binds[parts[0]] = {'bind': parts[1], 'ro': ro }
|
||||||
|
else:
|
||||||
|
self.module.fail_json(msg='volumes support 1 to 3 arguments')
|
||||||
|
|
||||||
self.lxc_conf = None
|
self.lxc_conf = None
|
||||||
if self.module.params.get('lxc_conf'):
|
if self.module.params.get('lxc_conf'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue