Docker allows deploying applications in isolated containers. Ansible is useful for building Docker images because it provides consistency and portability for configuring containers in the same way as configuring hosts. Ansible roles from Galaxy can be used to try applications before deploying them by building Docker images configured with Ansible plays that include the roles.