Installing Docker on Amazon Linux 2

Installation overview

https://aws.amazon.com/de/amazon-linux-2/release-notes/#Extras

The extras channel provides an AWS curated list of rapidly evolving technologies. These technologies may be updated more frequently than they would otherwise be in the “core” repositories of Amazon Linux 2.

The package for Docker is only available through extras and is enabled by default. When new versions of Docker are released, support will be provided only for the most current stable packages.

The extras channel contains multiple docker versions:

[ec2-user@ip-172-16-40-92 ~]$ sudo amazon-linux-extras list
  0  ansible2                 available    [ =2.4.2  =2.4.6 ]
  2  httpd_modules            available    [ =1.0 ]
  3  memcached1.5             available    [ =1.5.1 ]
  4  nginx1.12                available    [ =1.12.2 ]
  5  postgresql9.6            available    [ =9.6.6  =9.6.8 ]
  6  postgresql10             available    [ =10 ]
  8  redis4.0                 available    [ =4.0.5  =4.0.10 ]
  9  R3.4                     available    [ =3.4.3 ]
 10  rust1                    available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0 ]
 11  vim                      available    [ =8.0 ]
 13  ruby2.4                  available    [ =2.4.2  =2.4.4 ]
 15  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11 ]
 16  php7.1                   available    [ =7.1.22 ]
 17  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11 ]
 18  libreoffice              available    [ =5.0.6.2_15  =5.3.6.1 ]
 19  gimp                     available    [ =2.8.22 ]
 20  docker=latest            available    \
        [ =17.12.1  =18.03.1  =18.06.1 ]
 21  mate-desktop1.x          available    [ =1.19.0  =1.20.0 ]
 22  GraphicsMagick1.3        available    [ =1.3.29 ]
 23  tomcat8.5                available    [ =8.5.31  =8.5.32 ]
 24  epel                     available    [ =7.11 ]
 25  testing                  available    [ =1.0 ]
 26  ecs                      available    [ =stable ]
 27  corretto8                available    [ =1.8.0_192 ]
 28  firecracker              available    [ =0.11 ]
 29  golang1.11               available    [ =1.11.3 ]

Manual setup - linux-extras

sudo amazon-linux-extras install docker
sudo systemctl start docker
sudo usermod -a -G docker ec2-user docker

Manual setup - yum

sudo amazon-linux-extras enable

[ec2-user@ip-172-16-40-92 ~]$ sudo yum install docker
Geladene Plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                         | 2.4 kB  00:00:00
Abhängigkeiten werden aufgelöst
--> Transaktionsprüfung wird ausgeführt
---> Paket docker.x86_64 0:18.06.1ce-5.amzn2 markiert, um installiert zu werden
--> Abhängigkeit pigz wird für Paket docker-18.06.1ce-5.amzn2.x86_64 verarbeitet
--> Abhängigkeit libcgroup wird für Paket docker-18.06.1ce-5.amzn2.x86_64 verarbeitet
--> Abhängigkeit libltdl.so.7()(64bit) wird für Paket docker-18.06.1ce-5.amzn2.x86_64 verarbeitet
--> Transaktionsprüfung wird ausgeführt
---> Paket libcgroup.x86_64 0:0.41-15.amzn2 markiert, um installiert zu werden
---> Paket libtool-ltdl.x86_64 0:2.4.2-22.2.amzn2.0.2 markiert, um installiert zu werden
---> Paket pigz.x86_64 0:2.3.4-1.amzn2.0.1 markiert, um installiert zu werden
--> Abhängigkeitsauflösung beendet

Abhängigkeiten aufgelöst

==========================================================================================================================================
 Package                        Arch                     Version                                Paketquelle                         Größe
==========================================================================================================================================
Installieren:
 docker                         x86_64                   18.06.1ce-5.amzn2                      amzn2extra-docker                    37 M
Als Abhängigkeiten installiert:
 libcgroup                      x86_64                   0.41-15.amzn2                          amzn2-core                           65 k
 libtool-ltdl                   x86_64                   2.4.2-22.2.amzn2.0.2                   amzn2-core                           49 k
 pigz                           x86_64                   2.3.4-1.amzn2.0.1                      amzn2-core                           81 k

Transaktionsübersicht
==========================================================================================================================================
Installieren  1 Paket (+3 Abhängige Pakete)

Gesamte Downloadgröße: 37 M
Installationsgröße: 151 M
Is this ok [y/d/N]: y

sudo systemctl start docker
sudo usermod -a -G docker ec2-user docker

Ansible

main.yml

# Include Amazon Linux 2 tasks
- include_tasks: "Setup-AL2.yml"
  when:
    - not docker_offline_setup
    - ansible_distribution == "Amazon"
    - ansible_distribution_version == "2"

Setup-AL2.yml

- name: Enable amazon-linux-extras packages
  shell: "amazon-linux-extras enable "
  become: yes
  loop: ""