Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a shell command inside a running Docker container using Ansible

I want to execute shell commands, for eg: a "wget" command inside a running docker container using Ansible. This is the playbook I am trying to execute

---

- name: Enter into a running container and run a command
  docker_container:
    name: centos_conatainer
    state: started
    image: centos
    command: wget https://downloadlink.com

This stops the container and also it is not downloading the file. Is this the right way to execute shell commands using docker_container module, or is there any other way to do this using Ansible?

like image 473
shwetha Avatar asked Jul 18 '16 09:07

shwetha


1 Answers

You are looking for the Ansible equivalent of the docker exec command-line.

Command in ansible docker_container is the equivalent of the command option in the docker run command-line.

It doesn't appear that this new Ansible module has support for this. You'll just have to use the generic Ansible command.

Example:

- name: Enter into a running container and run a command
  command: docker exec centos_container wget https://downloadlink.com
like image 98
Michael Avatar answered Oct 07 '22 04:10

Michael