Awesome Open Source
Awesome Open Source

Ansible Role for Docker CE (Community Edition)

IMPORTANT! Even if this role does not list support for some distribution versions it might still work.

Ansible Role GitHub tag Ansible Quality Downloads License: MIT Build Status

This Ansible role installs and configures Docker CE (Community Edition) on several different Linux distributions. The goal is to let the user of this role to just care about how Docker shall be installed and configured and hide the differences that exists in the different distributions.


  • One way to install and configure Docker CE across supported Linux distributions.
  • Support install of Docker SDK and Docker Compose.
  • Best effort support of installations of Docker plugins.
  • Best effort uninstall of Docker CE and related configuration
  • Do tweaks etc to avoid buggy or non-working configurations in some supported distributions.
  • Ease handling of setting up Docker according to Center of Internet Security (CIS) documentation.

Supported Distributions

  • AlmaLinux
  • CentOS
  • Debian
  • Fedora
  • Linux Mint (based on Ubuntu).
  • Raspbian (based on Debian)
  • RHEL
  • Ubuntu

NB: Docker does not officially support Docker CE on this distribution and some features might/will not work.


See changelog here

Ansible Compatibility

  • 2.10 or later

For this role to support multiple Ansible versions it is not possible to avoid all Ansible deprecation warnings. Read Ansible documentation if you want to disable deprecation warnings.

This role tries to support the latest and previous major release of Ansible version. For supported Ansible versions see here


No additional requirements.

Role Variables

Variables related to this role are listed here



Example Playbook

Following sub sections show different kind of examples to illustrate what this role supports.


- hosts: docker
    - role: haxorof.docker_ce

Configure Docker daemon to use proxy

- hosts: docker
      HTTP_PROXY: http://localhost:3128/
      NO_PROXY: localhost,,
    - haxorof.docker_ce

Ensure Ansible can use Docker modules after install

- hosts: test-host
    docker_sdk: true
    docker_compose: true
    - haxorof.docker_ce
    - name: Test hello container
      become: yes
        name: hello
        image: hello-world

    - name: Test hello service
      become: yes
        project_name: hello
          version: '3'
              image: "hello-world"

On the road to CIS security compliant Docker engine installation

This minimal example below show what kind of role configuration that is required to pass the Docker bench checks. However this configuration setup devicemapper in a certain way which will create logical volumes for the containers. Simplest is to have at least 3 GB of free space available in the partition. Since Docker v17.06 it is possible to just set the storage option dm.directlvm_device to make Docker create the necessary volumes:

- hosts: docker
      - type: authz
        alias: opa-docker-authz
        name: openpolicyagent/opa-docker-authz-v2:0.4
        args: opa_args="-policy-file /opa/policies/authz.rego"
    docker_enable_audit: yes
      icc: false
      log-driver: journald
      userns-remap: default
      live-restore: true
      userland-proxy: false
      no-new-privileges: true
    - haxorof.docker_ce

Because the configuration above requires Linux user namespaces to be enabled then additional GRUB arguments might be needed. Example below show one example what changes that might be needed and reboot of the host is required for the changes to take full affect.


- hosts: docker
    - role: jtyr.grub_cmdline
          - namespace.unpriv_enable=1
          - user_namespace.enable=1
      become: yes
    - name: set user.max_user_namespaces
        name: user.max_user_namespaces
        value: 15000
        sysctl_set: yes
        state: present
        reload: yes
      become: yes

For a more complete working example on CentOS 7 have a look here.

Automated test matrix

Here is the latest test results of the automated test which is located in the tests directory:

Note! All distributions listed in test matrix below does not provided the latest released Docker CE version.

Last run: 2021-06-19 (Latest possible Docker CE release 20.10.7, Run with Ansible 3.4.0)

Test Suites

Suite ID Comment
s-1 t_config
s-2 t_channel Fail sometime since it might not be any nightly Docker CE build available
s-3 t_postinstall
s-4 t_devicemapper_config
s-5 t_auditd

Test Matrix

Symbol Definition
✔️ All tests passed
At least one test failed
No test done / Not yet tested
# s-1 s-2 s-3 s-4 s-5
almalinux/8 ✔️ ✔️ ✔️ ✔️
centos/7 ✔️ ✔️ ✔️ ✔️ ✔️
centos/8 ✔️ ✔️ ✔️ ✔️
generic/ubuntu1604 ✔️ ✔️ ✔️ ✔️ ✔️
generic/ubuntu1804 ✔️ ✔️ ✔️ ✔️ ✔️
generic/ubuntu2004 ✔️ ✔️ ✔️ ✔️
generic/debian9 ✔️ ✔️ ✔️ ✔️
generic/debian10 ✔️ ✔️ ✔️ ✔️
generic/fedora32 ✔️ ✔️ ✔️ ✔️
generic/fedora33 ✔️ ✔️ ✔️ ✔️
rhel/7 ✔️ ✔️ ✔️ ✔️ ✔️
rhel/8 ✔️ ✔️ ✔️ ✔️


This is an open source project under the MIT license.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Shell (232,627
Docker (33,932
Ansible (6,819
Ubuntu (3,345
Ansible Roles (2,184
Debian (1,968
Centos (758
Fedora (498
Rhel (145
Related Projects