AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible Install Docker: Automate Docker Installation on Linux (Complete Guide)

By Luca Berton · Published 2024-01-01 · Category: installation

How to install Docker on Linux servers using Ansible. Automate Docker Engine installation on Ubuntu, Debian, RHEL, CentOS with a complete playbook. Add users to docker group, configure daemon.

Ansible Install Docker: Automate Docker Installation on Linux (Complete Guide)

Automate Docker Engine installation across your entire fleet using Ansible. This guide provides complete, tested playbooks for Ubuntu, Debian, RHEL, CentOS, and Fedora — from adding the repository to configuring the Docker daemon.

Quick Playbook (Ubuntu/Debian)

RHEL / CentOS / Fedora Playbook

Multi-OS Playbook (Handles Any Distro)

Configure Docker Daemon

Add Users to Docker Group

Install Docker Compose (Standalone)

Docker Compose v2 is included as a Docker plugin (docker compose). For the standalone binary:

Verify Installation

Install Specific Docker Version

Complete Role Structure

For production use, organize as an Ansible role:

Or use the popular community role:

FAQ

How do I install Docker with Ansible?

Add the official Docker repository, install docker-ce, docker-ce-cli, and containerd.io packages, then start and enable the Docker service with ansible.builtin.systemd. See the complete playbooks above for Ubuntu/Debian and RHEL/CentOS.

Can Ansible install Docker on multiple servers at once?

Yes. Define your target servers in the Ansible inventory, then run the Docker installation playbook against all of them simultaneously. Ansible handles parallel execution across your entire fleet.

How do I add a user to the Docker group with Ansible?

Use the ansible.builtin.user module with groups: docker and append: true. This adds the user to the docker group without removing them from existing groups, allowing them to run Docker commands without sudo.

Should I use a role or write my own playbook for Docker?

For quick setups, the playbooks above work well. For production, use the geerlingguy.docker Galaxy role or create your own role. Roles provide better organization, reusability, and variable management.

How do I install Docker Compose with Ansible?

Docker Compose v2 is included as a Docker plugin when you install docker-compose-plugin. Run docker compose version to verify. For the standalone binary, download it with get_url from the GitHub releases page.

Conclusion

Automating Docker installation with Ansible ensures consistent, repeatable deployments across your infrastructure. Use the OS-specific playbooks for quick setup, configure the Docker daemon for production logging and networking, and add users to the docker group for secure, sudo-free Docker access.

Related ArticlesAnsible Docker Containers: community.docker GuideAnsible on AWS: Automate EC2, S3, IAMAnsible Roles: Create Reusable Automation

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home