# call Dockerfiles inside ansible

**URL:** <https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401>\
**Category:** Ansible Project\
**Created:** [August 22, 2018, 5:14pm UTC](https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401 "2018-08-22T17:14:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe\_pinto](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@joe\_pinto](https://forum.ansible.com/u/joe_pinto)\
**Post date:** [August 22, 2018, 5:14pm UTC](https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401/1 "2018-08-22T17:14:35Z")

</div>

I have one Dockerfile

I have tried :

- name: build docker image  
command: docker build -t ansibleum /ze/Dockerfile

But the image was not created)

ansible-playbook old\_copiash.yml -f 1

PLAY [Transfer and execute a script.] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [host2]  
TASK [Transfer the script] \*\*\*\*\*\*\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*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
host2 : ok=4 changed=2 unreachable=0 failed=0  
[root@localhost ze]# docker ps -q -a

I can I build an image using docker ?

thanks in advance

josé pinto

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [November 12, 2018, 9:26pm UTC](https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401/2 "2018-11-12T21:26:42Z")

</div>

From seeing the available Docker modules, I’d say you can build Docker images, I’m just not sure if you can use Ansible to execute Dockerfiles. The documentation would say so, but it’s a bit unclear as to how to achieve this. Not enough good examples.

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [November 12, 2018, 9:36pm UTC](https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401/3 "2018-11-12T21:36:32Z")

</div>

Maybe this works: [https://docs.ansible.com/ansible-container/migrating.html#migrating-from-a-dockerfile](https://docs.ansible.com/ansible-container/migrating.html#migrating-from-a-dockerfile)

---

<div class="post-metadata">

**Author:** ![Thad\_Guidry](https://avatars.discourse-cdn.com/v4/letter/t/35a633/32.png) [@Thad\_Guidry](https://forum.ansible.com/u/Thad_Guidry)\
**Post date:** [November 12, 2018, 10:42pm UTC](https://forum.ansible.com/t/call-dockerfiles-inside-ansible/28401/4 "2018-11-12T22:42:24Z")

</div>

Yes, I would highly recommend you start using Ansible Container to build your docker containers. You can even use the Ansible template module to automatically create the compose files you’ll need.  
[https://www.ansible.com/blog/ansible-container-project](https://www.ansible.com/blog/ansible-container-project)
