Feature request: support Docker data containers

Hi!

This is a follow-up to github issue https://github.com/ansible/ansible/issues/6395.

Docker data containers are containers that don’t run a specific process, and exist only to hold a volume which will then be shared by “real” containers using the --volumes-from run option.
For instance, to host a MySQL database on Docker, one might do something along the lines of:

docker run -name data -v /var/lib/mysql ubuntu true
docker run -name mysql --volumes-from data mysql mysqld_safe

The whole point is to be able to upgrade the MySQL container without having to transfer the data to a new container.
The new container just has to use the same --volumes-from.

For more information about volumes and data containers:

I would love to be able to support data containers with Ansible. Currently, if I ask Ansible to create a data container, it will work, but it won’t be idempotent: since the container exits right away, on the next run, Ansible will try to run it again, and fail (since it is a named, i.e. singleton, container). I found two workarounds:

  • run a dummy command in the data container, e.g. “while true; do sleep 1000000; done”
  • shellout to “docker inspect” to check if the container exists, allow failure, register an event; then declare another fact to run only when the event failed, to create the container
    Both feel really hackish.

IMVHO, the best solution would be to alter the semantics of the Docker module, so that containers can be either “running” or “present”.
Currently, “present” means “the container should be here, and it should be running”.
IMVHO, it would make more sense if that was actually triggered by “running”, while “present” would mean “the container has to exist, but we don’t care about its state, running or stopped”.

(But I don’t know if we want to break the current state definitions, so I don’t know if such a change would be acceptable. In any case, if a container already exists, “present” should start it instead of creating if it already exists!)

Let me know what you think!

Pull requests would be welcome!

I’d love to submit one, but I don’t know the policy about changing existing semantics.
If it’s OK to change semantics, I’d change the way “present” behaves in the Docker module.
Otherwise I’d propose a different workaround.
(And I asked on the ML because the github issue explicitly mentions “bring that on ansible-devel” :-))

Thanks!

I’d basically look at it like (A) docker is pretty new and still figuring out semantics, (B) the existing module existed before some things were established, and (C) you guys probably know best.

While I wouldn’t want to see things break in say, EC2 modules, Docker being pre-1.0 this seems more acceptable to me.

Feel free to do what you think needs to be done.

(Also also thanks for including the wider devel list audience!)