Question: I run a Ansible Playbook that gathers machine specific information and store the date within a file. One for each host. So I end up with a buch of files which should now be send to my Docker-Based Application for further processing.

Actuall I need to store it in a specific folder and create a volume so the container is able to read the files.

This requires the existence/creation of /tmp/incoming ...
Now if the Monitor app gets moved or a second Instance is needed, you'll have to access the filesystem and create the dirctory.

So I'd like to create a more dynamic volume:

```
docker volume create --name monitor-incoming:/var/www/monitor/incoming

```

Now Docker containers will be able to access the volume. But can I use Ansible to "copy" the files to this remote volume ? Sending them to monitor-incoming instead of /tmp/incoming ?

Answer: 
I don't have a docker environment to test this out, but I think you could do it from the host with a `docker run` on a `bash` image that:

* Binds the host's directory in which the file you want to copy is (I assumed we are copying `/path/to/filename/on/host`). I bound that directory to `/tmp/source/` inside the container.
* Binds the `monitor-incoming` volume somewhere in the container. I chose to bind it to `/tmp/destination/`.
* Runs a simple `cp` command (since the entrypoint of the `bash` image is `bash` itself, we just have to add the command to run).

Here is the command:

```
docker run \
  --mount source=monitor-incoming,target=/tmp/destination \
  --mount type=bind,source=/path/to/filename/on/host,target=/tmp/source \
  bash:4.4 \
  cp "/tmp/source" "/tmp/destination/path/to/destination/inside/volume/"

```

This is not tested, but I think something along those lines should work. Notice that if that script is used fairly frequently, you should probably have a container dedicated to that task rather than call `docker run` many times.

I'm not sure if there's a more direct way that would not involve running `cp` inside a container...
I wish we could do it with a built-in module, but unless we have one, you can add a file into a named volume in a single task:

```
- name: actual config file is in the volume
  command:
    cmd: docker run --rm -iv your-config-volume:/v busybox sh -c 'cat > /v/config.yml'
    stdin: "{{ lookup('file', 'config.yml') | regex_replace('\\r\\n', '\\n') }}"

```

Here we use [command module](https://docs.ansible.com/ansible/latest/modules/command_module.html) to create a temporary container with the `your-config-volume` volume attached.

The `sh -c 'cat > /v/config.yml'` command saves all `stdin` into a file.

Finally, we set `stdin` to be the `config.yml` file from your role.

> 
> The `regex_replace('\\r\\n', '\\n')` part is required only if you run Windows.
> 
> 
>