Copy file to docker container via Ansible
1.2k views Asked by Ali AtI want to copy a file to a docker container, as one of my Ansible playbook steps. I create the file with jinja2 "template". I can copy the file in /tmp/ and the run a command to copy it to the docker container, such as:
`docker cp /tmp/config.json my_image:/app/config/path/`
But I'm looking for the better way not to use "/tmp" or like that.
1
Ansible has a
docker
connection plugin that you can use to interact with existing containers in your playbook. For example, if I have a container namedmycontainer
:I can create an Ansible inventory like this that sets the
ansible_connection
variable tocommunity.general.docker
:Now I can target the container in a play like this: