Preparing Ansible to work with Docker
We need to make sure that Docker engine is up and running. Using the Ansible module with Docker requires installation of the following Python packages:
- docker-py - docker-compose
How to do it…
- Let's install the pip package
docker-py
in a version greater than 1.7.0. Ansible will use this Python library to interact with the Docker API:
$ pip install 'docker-py>=1.7.0'
- Let's install the
docker-compose
pip package in a version greater than 1.7.0. Ansible will use this to interact with Docker compose:
$ pip install 'docker-compose>=1.7.0'
- The Ansible module connects with the Docker API, as we mentioned earlier. Using parameters passed with tasks, we will be using a local Docker engine to create and manage Docker containers. It connects to a docker parameter using the parameter called
docker_host
. We can also set the environment variable toDOCKER_HOST
.
We should note that the default host used by the Ansible module is set as unix://var/run/docker.sock
, which...