Deploying Docker Containers with Ansible
Ansible can be used to manage Docker container upgrades and configuration changes. Docker has native ways to do this, namely Dockerfiles and Docker Compose. But sometimes there are reasons to start basic containers from an image and then manage configuration with Ansible or similar software. See Benefits of Managing Docker Containers with Automation Software.
In this page we'll discuss how to use Ansible to manage Docker containers.
How to Deploy a Container with Ansible
Ansible has modules to manage the Docker server, Docker containers, and Docker Compose. These modules are maintained by the community.
A dynamic inventory plugin for Docker exists. It retrieves the list of existing containers from Docker.
Docker modules and the Docker inventory plugin communicate with Docker using its API. The connection to the API can use a TSL connection and supports key authenticity verification.
To communicate with Docker API, Ansible needs a proper Python module installed on the Ansible node (
Several roles exist to deploy Docker and configure it. They can be found in Ansible Galaxy.
Further information can be found in Ansible documentation.
- Docker Guide.
- docker_container module.
Content initially contributed by Vettabase Ltd.