Closed r4j4h closed 8 years ago
This was fixed in commit https://github.com/ansible/ansible-modules-core/commit/e2d8d9d09a0a62d7aaa2ac915ef56d5a10fc673e. It's in devel and cherry-picked to stable-2.1 branch, though it has not made into an official release.
I tested again, just to make sure. Here's the playbook and results:
- name: docker_container testing
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: InfluxDB docker volume create
command: docker volume create --name resthomedb
ignore_errors: yes
- docker_container:
name: influxdb
image: influxdb
volumes:
- resthomedb:/var/lib/influxdb
ports:
- 8083:8083
- 8086:8086
It produces the following Mounts and Volumes:
"Mounts": [
{
"Name": "resthomedb",
"Source": "/mnt/sda1/var/lib/docker/volumes/resthomedb/_data",
"Destination": "/var/lib/influxdb",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
"Volumes": {
"/var/lib/influxdb": {}
},
Thanks folks for recognizing and having this issue fixed already!
For real! :fireworks: :tada: :)
@drajen reported this over at https://github.com/ansible/ansible/issues/16230 and I am forwarding here so it gets taken care of so no one else suffers data loss or 6 hours of their life for nothing.
ISSUE TYPE
COMPONENT NAME
docker_container
ANSIBLE VERSION
CONFIGURATION
None.
OS / ENVIRONMENT
Ubuntu Linux 14.04.4 source/destination
SUMMARY
In a 'volumes' array I would expect to use the same named volume syntax available with the docker command. Instead, docker_container creates a bind to a directory it created in cwd. I'm unable to identify if this is a bug in ansible or docker-py.
STEPS TO REPRODUCE
Steps to reproduce below:
This is the playbook:
EXPECTED RESULTS
Manual docker commands:
ACTUAL RESULTS
I left drajen's report unmodified, but I experienced the same problem. cwd or home directory is where volumes go.
I hypothesize the named volume is being misdetected as a relative path.
While I can see relative path being a common case, I think being explicit with a dot is a good way to go. Docker's -v argument supports named volumes on the left-hand side of the colon, so If it is not prefixed with a dot then a check to see if a valid volume matches the name should be made first. Maybe only that. Maybe if there is no volume it could fall back to defaulting to a relative path. Or maybe requiring the
.
to be explicit would be safer long-term..