title: Building Dockers with Ansible docker_image
body: <p>I'm trying to build a bunch of dockers on a machine using Ansible's <strong>docker_image</strong> module.</p>
  
  <p>I build 1 "base" docker image, which is used as the FROM image in all subsequent dockers images. This works when issuing the build commands manually as:</p>
  
  <pre><code>sudo docker build -t base .
  sudo docker build -t postgres .
  </code></pre>
  
  <p>But when I try to do the same with the Ansible module the second image (and all subsequent images that uses the "base" image) fails with the following error:</p>
  
  <pre><code>TASK: [Docker | Build postgres] ************************************ 
  failed: [192.168.1.120] =&gt; {"changed": true, "failed": true, "image_id": null}
  msg: Error: Error: image base:latest not found
  Log:Step 0 : FROM base
  
  
  FATAL: all hosts have already failed -- aborting
  </code></pre>
  
  <p>The entries in my Playbook is:</p>
  
  <pre><code>  - name: Docker | Build base
        docker_image: path="/home/xx/data/dockers/base/" name="base" state=present
  
      - name: Docker | Build postgres
        docker_image: path="/home/xx/data/dockers/postgresql/" name="postgres" state=present
  </code></pre>
  
  <p>When it fails the "base" image exists on the machine and I can verify it by checking <code>docker images</code>. The follow up images (in this case postgres) also builds without fail when doing a manual build. </p>
  
  <p>Relevant extracts from the Dockerfiles: </p>
  
  <p><strong>Base Dockerfile:</strong></p>
  
  <pre><code>FROM ubuntu
  
  MAINTAINER me
  
  RUN apt-get update
  
  RUN apt-get install -y \
      software-properties-common \
      wget \
      git \
      unzip \
      nano \
      vim-tiny
  
  CMD bash
  </code></pre>
  
  <p><strong>Postgres Dockerfile:</strong></p>
  
  <pre><code>FROM base
  
  MAINTAINER me
  
  RUN groupadd -r postgres &amp;&amp; useradd -r -g postgres postgres
  
  ...
  </code></pre>
  
  <p>So Ansible struggles to build an image using another image as a base image. I'm sure that the issue isn't with the Dockerfiles because I can build the images manually. I'm just trying to automate the build with Ansible and that's giving me the issue.</p>
  
  <p>Any advice? </p>