add docker examples

This commit is contained in:
Dany LE
2025-04-11 10:11:27 +00:00
parent 453233a25b
commit f135dcc118
704 changed files with 101445 additions and 21 deletions

View File

@ -42,14 +42,11 @@ jobs:
matrix:
distro:
- rockylinux9
- rockylinux8
- ubuntu2404
- ubuntu2204
- ubuntu2004
- debian12
- debian11
- debian10
- fedora39
- fedora40
steps:
- name: Check out the codebase.

View File

@ -1,6 +1,6 @@
# Ansible Role: Docker
[![CI](https://github.com/geerlingguy/ansible-role-docker/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-docker/actions?query=workflow%3ACI)
[![CI](https://github.com/geerlingguy/ansible-role-docker/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-docker/actions/workflows/ci.yml)
An Ansible Role that installs [Docker](https://www.docker.com) on Linux.
@ -34,11 +34,19 @@ docker_obsolete_packages:
- docker
- docker.io
- docker-engine
- docker-doc
- docker-compose
- docker-compose-v2
- podman-docker
- containerd
- runc
```
`docker_obsolete_packages` for different os-family:
- [`RedHat.yaml`](./vars/RedHat.yml)
- [`Debian.yaml`](./vars/Debian.yml)
A list of packages to be uninstalled prior to running this role. See [Docker's installation instructions](https://docs.docker.com/engine/install/debian/#uninstall-old-versions) for an up-to-date list of old packages that should be removed.
```yaml
@ -51,7 +59,7 @@ docker_restart_handler_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 `docker_service_manage` to `false`.
```yaml
docker_install_compose_plugin: false
docker_install_compose_plugin: true
docker_compose_package: docker-compose-plugin
docker_compose_package_state: present
```
@ -59,9 +67,10 @@ docker_compose_package_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.
```yaml
docker_install_compose: true
docker_compose_version: "1.26.0"
docker_install_compose: false
docker_compose_version: "v2.32.1"
docker_compose_arch: "{{ ansible_architecture }}"
docker_compose_url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-linux-{{ docker_compose_arch }}"
docker_compose_path: /usr/local/bin/docker-compose
```
@ -82,7 +91,7 @@ The main Docker repo URL, common between Debian and RHEL systems.
```yaml
docker_apt_release_channel: stable
docker_apt_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] {{ docker_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
docker_apt_repository: "deb [arch={{ docker_apt_arch }}{{' signed-by=/etc/apt/keyrings/docker.asc' if add_repository_key is not failed}}] {{ docker_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
docker_apt_ignore_key_error: True
docker_apt_gpg_key: "{{ docker_repo_url }}/{{ ansible_distribution | lower }}/gpg"
docker_apt_filename: "docker"
@ -115,7 +124,7 @@ A list of system users to be added to the `docker` group (so they can use Docker
```yaml
docker_daemon_options:
storage-driver: "devicemapper"
storage-driver: "overlay2"
log-opts:
max-size: "100m"
```

View File

@ -12,6 +12,9 @@ docker_obsolete_packages:
- docker
- docker.io
- docker-engine
- docker-doc
- docker-compose
- docker-compose-v2
- podman-docker
- containerd
- runc
@ -29,7 +32,7 @@ docker_compose_package_state: present
# Docker Compose options.
docker_install_compose: false
docker_compose_version: "v2.11.1"
docker_compose_version: "v2.32.1"
docker_compose_arch: "{{ ansible_architecture }}"
docker_compose_url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-linux-{{ docker_compose_arch }}"
docker_compose_path: /usr/local/bin/docker-compose

View File

@ -1,2 +1,2 @@
install_date: 'Wed 17 Jul 2024 02:03:32 PM '
version: 7.3.0
install_date: 'Fri 11 Apr 2025 09:32:24 AM '
version: 7.4.7

View File

@ -22,6 +22,7 @@ galaxy_info:
- bionic
- focal
- jammy
- noble
- name: Alpine
version:
- all

View File

@ -1,7 +1,7 @@
---
- name: Converge
hosts: all
become: true
# become: true
pre_tasks:
- name: Update apt cache.

View File

@ -8,7 +8,7 @@ driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux8}-ansible:latest"
image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw

View File

@ -0,0 +1,51 @@
---
- name: Verify Docker Role
hosts: all
tasks:
- name: Verify Docker binary is available
command: docker version
register: docker_version_result
changed_when: false
failed_when: docker_version_result.rc != 0
- name: Show Docker version details
debug:
msg: >
Docker Version Output:
{{ docker_version_result.stdout_lines | join('\n') }}
- name: Verify Docker service is running
command: systemctl is-active docker
register: docker_service_status
when: ansible_service_mgr == 'systemd'
changed_when: false
failed_when: docker_service_status.stdout.strip() != "active"
- name: Display Docker service status
debug:
msg: "Docker service is {{ docker_service_status.stdout.strip() }}"
when: ansible_service_mgr == 'systemd'
- name: Pull the 'hello-world' image
command: docker pull hello-world
register: docker_pull_result
changed_when: true
failed_when: docker_pull_result.rc != 0
- name: Show result of pulling the 'hello-world' image
debug:
msg: >
Pulling 'hello-world' completed with output:
{{ docker_pull_result.stdout_lines | join('\n') }}
- name: Run a test container (hello-world)
command: docker run --rm hello-world
register: docker_run_result
changed_when: true
failed_when: docker_run_result.rc != 0
- name: Display test container output
debug:
msg: >
Running 'hello-world' container completed with output:
{{ docker_run_result.stdout_lines | join('\n') }}

View File

@ -1,4 +1,22 @@
---
- name: Ensure apt key is not present in trusted.gpg.d
ansible.builtin.file:
path: /etc/apt/trusted.gpg.d/docker.asc
state: absent
- name: Ensure old apt source list is not present in /etc/apt/sources.list.d
ansible.builtin.file:
path: "/etc/apt/sources.list.d/download_docker_com_linux_{{ docker_apt_ansible_distribution | lower }}.list"
state: absent
- name: Ensure the repo referencing the previous trusted.gpg.d key is not present
apt_repository:
repo: "deb [arch={{ docker_apt_arch }} signed-by=/etc/apt/trusted.gpg.d/docker.asc] {{ docker_repo_url }}/{{ docker_apt_ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
state: absent
filename: "{{ docker_apt_filename }}"
update_cache: true
when: docker_add_repo | bool
- # See https://docs.docker.com/engine/install/debian/#uninstall-old-versions
name: Ensure old versions of Docker are not installed.
package:
@ -17,13 +35,13 @@
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
mode: "0755"
- name: Add Docker apt key.
ansible.builtin.get_url:
url: "{{ docker_apt_gpg_key }}"
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
mode: "0644"
force: false
checksum: "{{ docker_apt_gpg_key_checksum | default(omit) }}"
register: add_repository_key

View File

@ -1,10 +1,7 @@
---
- name: Ensure old versions of Docker are not installed.
package:
name:
- docker
- docker-common
- docker-engine
name: "{{ docker_obsolete_packages }}"
state: absent
- name: Add Docker GPG key.

View File

@ -1,2 +1,3 @@
---
docker_packages: "docker"
docker_compose_package: docker-cli-compose

View File

@ -0,0 +1,14 @@
---
# Used only for Debian/Ubuntu (Debian OS-Family)
# https://docs.docker.com/engine/install/debian/#uninstall-old-versions
docker_obsolete_packages:
- docker
- docker.io
- docker-engine
- docker-doc
- docker-compose
- docker-compose-v2
- podman-docker
- containerd
- runc

View File

@ -0,0 +1,14 @@
---
# Used only for Fedora/Rocky (RedHat OS-Family)
# https://docs.docker.com/engine/install/fedora/#uninstall-old-versions
# https://docs.docker.com/engine/install/centos/#uninstall-old-versions
docker_obsolete_packages:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine