Installing Docker Engine on Debian Bullseye as an Ansible playbook

Docker Engine is an open source containerization technology for building and containerizing our applications. Docker Engine acts as a client-server application with a server with a long-running daemon process dockerd and APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon. Docker Engine is available on a variety of Linux platforms, macOS and Windows 10 through Docker Desktop, and as a static binary installation. Docker Engine is the industry’s de facto container runtime that runs on various Linux (CentOS, Debian, Fedora, Oracle Linux, RHEL, and Ubuntu) and Windows Server operating systems.

Here’s an example playbook that we can use to install Docker Engine on Debian Bullseye after the base OS installation.

This is just a simple playbook, but as the industry standard it should be compiled to a role to be more modular and reusable.

---
- name: Install Docker Engine
  hosts: all
  become: yes

  tasks:
    - name: Install required packages
      apt:
        name:
          - apt-transport-https
          - ca-certificates
          - curl
          - gnupg2
          - software-properties-common

    - name: Add Docker GPG key
      apt_key:
        url: https://download.docker.com/linux/debian/gpg
        state: present

    - name: Add Docker repository
      apt_repository:
        repo: deb [arch=amd64] https://download.docker.com/linux/debian bullseye stable
        state: present

    - name: Install Docker Engine
      apt:
        name:
          - docker-ce
          - docker-ce-cli
          - containerd.io

    - name: Add user to docker group
      user:
        name: "{{ ansible_user }}"
        groups: docker

    - name: Start Docker service
      service:
        name: docker
        state: started

This playbook will install the required packages, add the Docker GPG key, add the Docker repository, install the Docker Engine, add our user to docker group and finally start Docker service.

2 thoughts on “Installing Docker Engine on Debian Bullseye as an Ansible playbook

Leave a comment