Run Commands On Docker Containers With Ansible

This post will show you how to use Ansible to deploy a container and run a command once the container starts.

Our previous posts showed how to get started with Ansible and the Docker module to deploy containers and volume.


In the below playbook, I am deploying a new container and using the command option to run a command when the container starts. The command that I’m using will keep the container running and will not exit.

- hosts: localhost

    - name: Create a data container
        name: web1
        image: ubuntu:latest
          - tail -f /dev/null