# How to docker exec in ansible?

**URL:** <https://forum.ansible.com/t/how-to-docker-exec-in-ansible/22668>\
**Category:** Ansible Project\
**Created:** [September 29, 2016, 2:27am UTC](https://forum.ansible.com/t/how-to-docker-exec-in-ansible/22668 "2016-09-29T02:27:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joaquin\_Menchaca](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Joaquin\_Menchaca](https://forum.ansible.com/u/Joaquin_Menchaca)\
**Post date:** [September 29, 2016, 2:27am UTC](https://forum.ansible.com/t/how-to-docker-exec-in-ansible/22668/1 "2016-09-29T02:27:45Z")

</div>

I would like to build a container then run some commands on it…

- name: Log into DockerHub  
docker\_login:  
username: “{{docker\_hub\_username}}”  
password: “{{docker\_hub\_password}}”  
email: “{{docker\_hub\_email}}”
- name: Build Foo Container  
docker:  
name: foo  
image: gobaltoops/foo:{{ git\_hash\_short }}  
state: reloaded  
pull: always  
command: bash “{{ app\_root }}”/“{{ config\_path }}”/“{{ app\_env }}”/wrapper.sh  
volumes:
- “{{ foo\_base\_dir }}/templates:/templates”
- “{{ foo\_base\_dir}}/logs:{{ app\_root }}/logs”
- “{{ foo\_base\_dir }}/target:{{ app\_root }}/output”  
env:  
APP\_ROOT: “{{ app\_root }}”

I would then like to run after:

docker exec -t foo config arg1  
docker exec -t foo migrate source  
docker exec -t foo build $GIT\_HASH\_SHORT

I tried this, but it didn’t work:

- hosts: foo  
connection: docker  
tasks:

- command: config arg1

- command: migrate source

- command: build {{ git\_hash\_short }}
