title: How to launch Docker Containers using Ansible
body: <p>I am writing a playbook where I want to build and image and start some containers for that image. I was able to build an image but my containers are not getting started. 
  They are being created successfully but not in running state.</p>
  
  <p>Can someone help what am i missing?</p>
  
  <p></p>
  
  <pre><code>- name: Manage Docker instances via Ansible
    hosts: shashank-VM
    connection: local
    become: yes
    become_method: sudo
    tasks:
      - name: Building an image from Dockerfile
        docker_image:
          build:
            path: .
            pull: yes
          name: web
          source: build
  
      - name: Starting Docker Containers
        docker_container:
          name: my-app-{{ item }}
          image: web:latest
          state: started
        with_sequence: count=4
  </code></pre>
  
  <p>From the below you can see the containers are created but if i do sudo docker ps I don't see anything.</p>
  
  <pre><code>TASK [Starting Docker Containers] ************************************************************************************************************
  /usr/lib/python2.7/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.25.9) or chardet (3.0.4) doesn't match a supported version!
    RequestsDependencyWarning)
  changed: [shashank-VM] =&gt; (item=1)
  changed: [shashank-VM] =&gt; (item=2)
  changed: [shashank-VM] =&gt; (item=3)
  changed: [shashank-VM] =&gt; (item=4)
  </code></pre>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  shashank@shashank-VM:~/docker_project$ sudo docker ps -a
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
  d5b586266f15        web_new             "/bin/bash"         2 minutes ago       Exited (0) 2 minutes ago                       myvm-app-4
  ea45cc1fcf3c        web_new             "/bin/bash"         2 minutes ago       Exited (0) 2 minutes ago                       myvm-app-3
  1e685f3d1368        web_new             "/bin/bash"         2 minutes ago       Exited (0) 2 minutes ago                       myvm-app-2
  5d03750c3fd2        web_new             "/bin/bash"         2 minutes ago       Exited (0) 2 minutes ago                       myvm-app-1
  shashank@shashank-VM:~/docker_project$ sudo docker run -d web_new
  6e937d7a8e75c04ea9dc6769fa41b00f5bf455e6f947f002d181d105b94c7265
  shashank@shashank-VM:~/docker_project$ sudo docker ps
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  shashank@shashank-VM:~/docker_project$ sudo docker ps -a
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
  6e937d7a8e75        web_new             "/bin/bash"         14 seconds ago      Exited (0) 13 seconds ago                       agitated_bartik
  </code></pre>
  
  <p>Dockerfile content -</p>
  
  <pre><code>FROM debian:8.5
  RUN apt-get update
  RUN apt-get install -y nginx
  RUN echo 'Default page. Nginx is in your container. ' \
  &gt;/usr/share/nginx/html/index.html
  EXPOSE 8085
  </code></pre>