sorrowless.docker
Ansible Role: Docker
This is an Ansible role that installs Docker on Linux systems.
Requirements
There are no specific requirements.
Role Variables
Below are the available variables along with their default values (see defaults/main.yml
):
- docker_edition: Choose either 'ce' for Community Edition or 'ee' for Enterprise Edition.
- docker_version: Specify the Docker version, for example: '=5:23.0.2-1
ubuntu.20.04focal' - docker_packages:
- "docker-{{ docker_edition }}{{ docker_version }}"
- "docker-{{ docker_edition }}-cli{{ docker_version}}"
- "docker-{{ docker_edition }}-rootless-extras{{ docker_version}}"
- "containerd.io"
- docker_packages_state: Controls the state of Docker packages. Use
present
to install,absent
to uninstall, andlatest
for the latest version. If the Docker package updates, the Docker daemon restarts automatically.
Docker Service Variables
- docker_service_manage: Set to
true
to manage the Docker service. Set tofalse
if you're installing Docker inside a container without a process manager. - docker_service_state: Should be set to
started
to keep the service running. - docker_service_enabled: Set to
true
to ensure Docker starts on boot. - docker_restart_handler_state: Automatically set to
restarted
when the Docker package is updated.
Docker Compose Installation Variables
docker_install_compose_plugin: Set to
false
if you want to install the Docker Compose plugin.docker_compose_package: The package name for the Docker Compose plugin.
docker_compose_package_state: Controls the state of the Compose plugin.
docker_install_compose: Set to
true
to install Docker Compose as a standalone application.docker_compose_version: Specify the version to install, e.g., "1.26.0".
docker_compose_arch: Set according to your architecture.
docker_compose_path: Path where Docker Compose will be installed. Default is
/usr/local/bin/docker-compose
.
Repository Control Variables
- docker_add_repo: Set to
true
to add the official Docker repository. Set tofalse
to use the default packages or manage the repo yourself.
Repository URL Variables
- docker_repo_url: The base URL for the Docker repository, used for both Debian and RHEL systems.
APT Variables (for Debian/Ubuntu)
- docker_apt_release_channel: Set to
stable
, but can be changed tonightly
. - docker_apt_arch: Architecture setting based on your system's architecture.
- docker_apt_repository: Specifies the repository for installation.
- docker_apt_ignore_key_error: Set to
true
to ignore key errors. - docker_apt_gpg_key: URL for the GPG key.
- docker_apt_filename: Defines the filename for the source list.
YUM Variables (for RedHat/CentOS)
- docker_yum_repo_url: URL for the Docker YUM repository.
- docker_yum_repo_enable_nightly: Set to '1' to enable the Nightly repo.
- docker_yum_repo_enable_test: Set to '1' to enable the Test repo.
- docker_yum_gpg_key: URL for the GPG key.
User Management Variables
- docker_users: List of system users who will be added to the
docker
group for access.
Docker Daemon Options
- docker_daemon_options: Configure custom options for the Docker daemon.
Registry Login Variables
To log into a Docker registry, define these variables:
- docker_registry_url
- docker_registry_user
- docker_registry_password
Using with Ansible and the Docker Python Library
If you want to build Docker images and manage containers using Ansible, you can add the Docker Python library by using the geerlingguy.pip
role:
- hosts: all
vars:
pip_install_packages:
- name: docker
roles:
- geerlingguy.pip
- geerlingguy.docker
To configure Docker Swarm, set docker_swarm_configure: true
for all nodes and docker_swarm_manager: true
for manager nodes. Ensure inventory_hostname
matches ansible_hostname
for remote nodes.
Dependencies
There are no dependencies.
Example Playbook
- hosts: all
roles:
- geerlingguy.docker
License
MIT / BSD
Sponsors
- We Manage: Supporting start-ups and established businesses in growth through sustainable infrastructure practices.
Sponsors support Jeff Geerling on GitHub Sponsors. You can also support his work to help improve these Ansible open source projects!
Author Information
This role was created in 2017 by Jeff Geerling, author of Ansible for DevOps. The role has been adapted for specific needs by Stan Bogatkin.
Docker for Linux.
ansible-galaxy install sorrowless.docker