Docker CE installation and configuration with user group management.
The Docker role installs Docker Community Edition (CE) from the official Docker repository, configures the Docker daemon, manages user permissions, and ensures the Docker service is running and enabled. It provides a complete Docker setup ready for container development and deployment.
- Ubuntu 20.04 LTS or later
- Ansible 2.12 or later
- Common role (automatically included as dependency)
- Internet connectivity for Docker repository access
The following variables can be set in defaults/main.yml:
# Docker packages to install
docker_packages:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
# Docker repository configuration
docker_apt_repository: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
docker_gpg_key_url: "https://download.docker.com/linux/ubuntu/gpg"
docker_gpg_key_id: "9DC858229FC7DD38854AE2D88D81803C0EBFCD88"
# User configuration
target_user: "{{ ansible_user }}"
docker_group: "docker"
# Service configuration
docker_service_enabled: true
docker_service_state: "started"docker_packages: List of Docker packages to installdocker_apt_repository: APT repository configuration for Dockerdocker_gpg_key_url: URL for Docker's GPG signing keydocker_gpg_key_id: Expected GPG key ID for verificationtarget_user: User to add to docker groupdocker_group: Docker group namedocker_service_enabled: Whether to enable Docker service on bootdocker_service_state: Desired state of Docker service
common: Base system setup and essential packages
---
- hosts: servers
become: yes
roles:
- common
- docker- Official Repository: Installs Docker from official Docker repository
- GPG Verification: Validates repository signing key for security
- Complete Installation: Installs Docker CE, CLI, containerd, and plugins
- User Management: Adds specified user to docker group for non-root access
- Service Management: Configures and starts Docker daemon
- Validation: Verifies Docker installation and functionality
The role implements several security measures:
- GPG Key Verification: Validates Docker repository signing key
- Official Sources: Uses only official Docker repositories
- User Group Management: Properly configures docker group permissions
- Service Security: Ensures Docker daemon is properly configured
After installation, the following will be available:
dockercommand for container managementdocker-compose(via plugin) for multi-container applicationsdocker buildxfor advanced building capabilities- User access to Docker without sudo (after logout/login)
The role includes validation tasks that verify:
- Docker packages are installed correctly
- Docker service is running
- User is added to docker group
- Docker daemon is responding to commands
Common issues and solutions:
- Permission denied: Ensure user logout/login after docker group addition
- Service not starting: Check system resources and Docker daemon logs
- Repository issues: Verify network connectivity and GPG key validation
MIT
Development Team - Internal Use