Skip to content

Latest commit

 

History

History
120 lines (85 loc) · 3.52 KB

File metadata and controls

120 lines (85 loc) · 3.52 KB

Docker Role

Docker CE installation and configuration with user group management.

Description

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.

Requirements

  • Ubuntu 20.04 LTS or later
  • Ansible 2.12 or later
  • Common role (automatically included as dependency)
  • Internet connectivity for Docker repository access

Role Variables

Available Variables

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"

Variable Descriptions

  • docker_packages: List of Docker packages to install
  • docker_apt_repository: APT repository configuration for Docker
  • docker_gpg_key_url: URL for Docker's GPG signing key
  • docker_gpg_key_id: Expected GPG key ID for verification
  • target_user: User to add to docker group
  • docker_group: Docker group name
  • docker_service_enabled: Whether to enable Docker service on boot
  • docker_service_state: Desired state of Docker service

Dependencies

  • common: Base system setup and essential packages

Example Playbook

---
- hosts: servers
  become: yes
  roles:
    - common
    - docker

Features

  • 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

Security

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

Post-Installation

After installation, the following will be available:

  • docker command for container management
  • docker-compose (via plugin) for multi-container applications
  • docker buildx for advanced building capabilities
  • User access to Docker without sudo (after logout/login)

Validation

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

Troubleshooting

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

License

MIT

Author Information

Development Team - Internal Use