Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 376
Hristo Stoyanov Avatar asked Aug 17 '15 06:08

Hristo Stoyanov


People also ask

How can you use Docker module in Ansible?

docker (dynamic inventory) Dynamically builds an inventory of all the available containers from a set of one or more Docker hosts. Ansible 2.1. 0 includes major updates to the Docker modules, marking the start of a project to create a complete and integrated set of tools for orchestrating containers.

What does Docker CP Command do?

The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If - is specified for either the SRC_PATH or DEST_PATH , you can also stream a tar archive from STDIN or to STDOUT .

How do I copy a module in Ansible playbook?

Copying Directories from Local to Remote You can also copy folders or directories using the Ansible copy module. If the 'src' path is a directory, then it will be copied recursively. Or the entire directory will be copied. There are two different variations for this task.

Does Ansible copy overwrite?

By default, the ansible copy module does a force copy to the destination and overwrites the existing file when present.


3 Answers

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

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

like image 98
Deepak Shenoy Avatar answered Oct 20 '22 02:10

Deepak Shenoy


Using ansible shell module helped:

  - name: copy db dump to localhost
    ansible.builtin.shell: docker cp container:/tmp/dump.sql /tmp/dump.sql
like image 41
rok Avatar answered Oct 20 '22 04:10

rok


  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.

like image 39
hostmaster Avatar answered Oct 20 '22 02:10

hostmaster