Hristo Stoyanov
Hristo Stoyanov

Reputation: 1698

Ansible docker module missing CP command?

The docker client offers the cp sub-command as explained here, which is very handy when one needs to copy a file into a container (note: this is somewhat analogous to Dockerfile ADD instruction in image building). In Docker 1.8 the cp command has been even expanded a bit.

However, reading the Ansible docker module documentation, it appears that this is missing? Here are my 2 questions:

  1. Did I misunderstand the Ansible documentation?
  2. if Ansible is missing the cp thing, has anyone found a workaround? I can think of something like using Ansible copy module to transport the files to the remote machine first, and then run there the native docker client with cp, but ideally Ansible's docker module would have done this in a single shot as part of the docker module?

Thanks in advance.

Upvotes: 6

Views: 7250

Answers (3)

rokpoto.com
rokpoto.com

Reputation: 10736

Using ansible shell module helped:

  - name: copy db dump to localhost
    ansible.builtin.shell: docker cp container:/tmp/dump.sql /tmp/dump.sql

Upvotes: 2

hostmaster
hostmaster

Reputation: 2150

  1. You didn't. Ansible's docker module does not support copying files or folders from a container.
  2. There is no simple way to do so. I mean you need a hack. Off the top of my head you can play with '-' argument for docker cp option.

However from my point of view if you wish to copy something into a container you're probably doing something wrong. Containers should be ephemeral.

Upvotes: 1

dshenoy
dshenoy

Reputation: 753

You can also use the synchronize command ~ examples provided in this link:

http://opensolitude.com/2015/05/26/building-docker-images-with-ansible.html

Upvotes: 4

Related Questions