haxorof.docker_ce

用于 Docker CE(社区版)的 Ansible 角色

重要提示! 即使此角色未列出对某些发行版版本的支持,它仍可能正常工作。

GitHub标签 Ansible角色 许可证:MIT 构建状态

这个 Ansible 角色用于在多种 Linux 发行版上安装和配置 Docker CE(社区版)。目标是让使用该角色的用户只需关心 Docker 如何安装和配置,而忽略不同发行版之间的差异。

ansible-galaxy role install haxorof.docker_ce

特性

  • 在支持的 Linux 发行版上安装和配置 Docker CE 的统一方法。
  • 支持 Docker SDK 和 Docker Compose 的安装。
  • 尽最大努力支持 Docker 插件的安装。
  • 尽最大努力卸载 Docker CE 及相关配置。
  • 在一些支持的发行版中进行调整,以避免出现错误或无效的配置。
  • 根据网络安全中心(CIS)的文档简化 Docker 的设置。

支持的发行版

注意! 以下列出的某些发行版版本仅安装了 Python 2.7,这些版本仅与 Ansible 版本低于 10.0.0(或 ansible-core 版本低于 2.17)兼容。因为在 Ansible 10.0.0(ansible-core 2.17)中取消了对 Python 2.7 的支持。

  • AlmaLinux1
  • Amazon Linux1
  • CentOS1
  • CentOS Stream
  • Debian
  • Fedora
  • Linux Mint1(基于 Ubuntu)。
  • Raspbian(基于 Debian)
  • RHEL
  • Rocky Linux1
  • Ubuntu

1 注意:Docker 并没有在该发行版上正式完全或部分支持 Docker CE,某些功能可能无法正常工作。

还有其他可能与此角色兼容的发行版,您可以通过将变量 docker_do_checks 设置为 no 来禁用发行版检查。

更新日志

更新日志请见 这里

Ansible 兼容性

  • ansible 9.0.0 或更高(ansible-core 2.16 或更高)

为了让这个角色支持多个 Ansible 版本,无法避免所有的 Ansible 弃用警告。如果您想要禁用 弃用警告,请查阅 Ansible 文档。

这个角色尝试支持 Ansible 版本的最新和前一个主要版本。有关支持的 Ansible 版本,请见 这里

Ansible 集合要求

如果仅安装了 ansible-core,则必须安装以下集合才能使角色正常工作:

  • ansible.posix
  • community.general

要求

没有其他要求。

角色变量

与此角色相关的变量列在 这里

依赖项

无。

示例剧本

以下子章节展示了不同类型的示例,以说明此角色支持的功能。

最简单的例子

- hosts: docker
  roles:
    - role: haxorof.docker_ce

配置 Docker 守护进程使用代理

- hosts: docker
  vars:
    docker_daemon_envs:
      HTTP_PROXY: http://localhost:3128/
      NO_PROXY: localhost,127.0.0.1,docker-registry.somecorporation.com
  roles:
    - haxorof.docker_ce

确保 Ansible 安装后可以使用 Docker 模块

- hosts: test-host
  vars:
    docker_sdk: true
    docker_compose: true
  roles:
    - haxorof.docker_ce
  post_tasks:
    - name: 测试 hello 容器
      become: yes
      docker_container:
        name: hello
        image: hello-world

    - name: 测试 hello 服务
      become: yes
      docker_service:
        project_name: hello
        definition:
          version: '3'
          services:
            hello:
              image: "hello-world"

朝着符合 CIS 安全标准的 Docker 引擎安装迈进

以下的简单示例展示了通过配置角色来通过 Docker 检查 的要求:

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

由于上述配置需要启用 Linux 用户命名空间,因此可能需要其他 GRUB 参数。以下示例展示了需要的更改,且必须重启主机以使更改生效。

# https://success.docker.com/article/user-namespace-runtime-error

- hosts: docker
  roles:
    - role: jtyr.grub_cmdline
      vars:
        grub_cmdline_add_args:
          - namespace.unpriv_enable=1
          - user_namespace.enable=1
      become: yes
  tasks:
    - name: 设置 user.max_user_namespaces
      sysctl:
        name: user.max_user_namespaces
        value: 15000
        sysctl_set: yes
        state: present
        reload: yes
      become: yes

有关 CentOS 7 上更完整的可运行示例,请查看 这里

自动化测试矩阵

这是最新的自动化测试结果,测试结果位于 tests 目录中:

注意! 测试矩阵中列出的所有发行版都未提供最新版本的 Docker CE。

测试套件

套件 ID 注释
s-1 t_config
s-2 t_postinstall
s-3 t_auditd

测试矩阵

符号 定义
:heavy_check_mark: 所有测试通过
:x: 至少一个测试失败 / 不支持
:heavy_minus_sign: 没有测试 / 尚未测试
# s-1 s-2 s-3 更新时间
AlmaLinux 8 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
AlmaLinux 9 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Amazon Linux 2 :heavy_check_mark: :x: :heavy_check_mark: 2024-08-02
Amazon Linux 2023 :heavy_check_mark: :x: :heavy_check_mark: 2024-08-02
CentOS Stream 9 :heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: 2024-08-02
Debian 11 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Debian 12 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Fedora 39 :heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: 2024-08-02
Fedora 40 :heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: 2024-08-02
Rocky Linux 8 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Rocky Linux 9 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Ubuntu 20.04 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Ubuntu 22.04 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-02
Ubuntu 24.04 :heavy_minus_sign: :heavy_minus_sign: :heavy_minus_sign: 2024-08-02
RHEL 8 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-12
RHEL 9 :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: 2024-08-12

许可证

这是一个开源项目,使用 MIT 许可证。

关于项目

Installs and configures Docker Community Edition (CE) on AlmaLinux/Rocky/CentOS/Fedora/RHEL/Ubuntu/Debian/Mint/Raspbian

安装
ansible-galaxy install haxorof.docker_ce
许可证
mit
下载
285.2k
拥有者