geerlingguy
ansible-role-docker

Ansible Role - Docker

Last updated Jul 2, 2026
2.3k
Stars
898
Forks
15
Issues
0
Stars/day
Attention Score
96
Language breakdown
No language data available.
Files click to expand
README

Ansible Role: Docker

CI

An Ansible Role that installs Docker on Linux.

Requirements

None.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
docker_edition: 'ce'
docker_packages:
  - "docker-{{ docker_edition }}"
  - "docker-{{ docker_edition }}-cli"
  - "docker-{{ docker_edition }}-rootless-extras"
  - "containerd.io"
  - docker-buildx-plugin
dockerpackagesstate: present

The docker_edition should be either ce (Community Edition) or ee (Enterprise Edition). You can also specify a specific version of Docker to install using the distribution-specific format: Red Hat/CentOS: docker-{{ docker_edition }}-<VERSION> (Note: you have to add this to all packages); Debian/Ubuntu: docker-{{ docker_edition }}=<VERSION> (Note: you have to add this to all packages).

You can control whether the package is installed, uninstalled, or at the latest version by setting dockerpackagesstate to present, absent, or latest, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play).

dockerobsoletepackages:
  - docker
  - docker.io
  - docker-engine
  - docker-doc
  - docker-compose
  - docker-compose-v2
  - podman-docker
  - containerd
  - runc

dockerobsoletepackages for different os-family:

A list of packages to be uninstalled prior to running this role. See Docker's installation instructions for an up-to-date list of old packages that should be removed.
dockerservicemanage: true
dockerservicestate: started
dockerserviceenabled: true
dockerservicestart_command: ""
dockerrestarthandler_state: restarted

Variables to control the state of the docker service, and whether it should start on boot. If you're installing Docker inside a Docker container without systemd or sysvinit, you should set dockerservicemanage to false.

dockerinstallcompose_plugin: true
dockercomposepackage: docker-compose-plugin
dockercomposepackage_state: present

Docker Compose Plugin installation options. These differ from the below in that docker-compose is installed as a docker plugin (and used with docker compose) instead of a standalone binary.

dockerinstallcompose: false
dockercomposeversion: "v2.32.1"
dockercomposearch: "{{ ansible_facts.architecture }}"
dockercomposeurl: "https://github.com/docker/compose/releases/download/{{ dockercomposeversion }}/docker-compose-linux-{{ dockercomposearch }}"
dockercomposepath: /usr/local/bin/docker-compose

Docker Compose installation options.

dockeraddrepo: true

Controls whether this role will add the official Docker repository. Set to false if you want to use the default docker packages for your system or manage the package repository on your own.

dockerrepourl: https://download.docker.com/linux

The main Docker repo URL, common between Debian and RHEL systems.

dockeraptrelease_channel: stable
dockeraptansibledistribution: "{{ 'ubuntu' if ansiblefacts.distribution in ['Pop!OS', 'Linux Mint'] else ansiblefacts.distribution }}"
dockeraptrepourl: "{{ dockerrepourl }}/{{ dockeraptansibledistribution | lower }}"
dockeraptgpgkey: "{{ dockerrepourl }}/{{ dockeraptansibledistribution | lower }}/gpg"
dockeraptfilename: "docker"

(Used only for Debian/Ubuntu.) You can switch the channel to nightly if you want to use the Nightly release.

dockeraptansible_distribution is a workaround for Ubuntu variants which can't be identified as such by Ansible, and is only necessary until Docker officially supports them.

You can change dockeraptrepo_url if you need to point Debian or Ubuntu systems at an internal mirror or cache. You can change dockeraptgpg_key to a different url if you are behind a firewall or provide a trustworthy mirror. dockeraptfilename controls the name of the source list file created in sources.list.d. If you are upgrading from an older (<7.0.0) version of this role, you should change this to the name of the existing file (e.g. downloaddockercomlinuxdebian on Debian) to avoid conflicting lists.

dockeryumrepourl: "{{ dockerrepourl }}/{{ 'fedora' if ansiblefacts.distribution == 'Fedora' else 'rhel' if ansiblefacts.distribution == 'RedHat' else 'centos' }}/docker-{{ dockeredition }}.repo"
dockeryumrepoenabletest: '0'
dockeryumgpgkey: "{{ dockerrepourl }}/{{ 'fedora' if ansiblefacts.distribution == 'Fedora' else 'rhel' if ansible_facts.distribution == 'RedHat' else 'centos' }}/gpg"

(Used only for RedHat/CentOS.) You can enable the Test repo by setting the respective vars to 1.

You can change dockeryumgpg_key to a different url if you are behind a firewall or provide a trustworthy mirror. Usually in combination with changing dockeryumrepository as well.

docker_users: []

A list of system users to be added to the docker group (so they can use Docker on the server). Example:

docker_users:
  - user1
  - user2
dockerdaemonoptions: {}

Custom dockerd options can be configured through this dictionary representing the json file /etc/docker/daemon.json. Example:

dockerdaemonoptions:
  storage-driver: "overlay2"
  log-opts:
    max-size: "100m"

Use with Ansible (and docker Python library)

Many users of this role wish to also use Ansible to then build Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the docker Python library using the geerlingguy.pip role:

- hosts: all

vars: pipinstallpackages: - name: docker

roles: - geerlingguy.pip - geerlingguy.docker

Dependencies

None.

Example Playbook

- hosts: all
  roles:
    - geerlingguy.docker

License

MIT / BSD

Sponsors

  • We Manage: Helping start-ups and grown-ups scaling their infrastructure in a sustainable way.
The above sponsor(s) are supporting Jeff Geerling on GitHub Sponsors. You can sponsor Jeff's work too, to help him continue improving these Ansible open source projects!

Author Information

This role was created in 2017 by Jeff Geerling, author of Ansible for DevOps.

🔗 More in this category

© 2026 GitRepoTrend · geerlingguy/ansible-role-docker · Updated daily from GitHub