Ubuntu配置阿里云docker apt源

一、配置阿里云docker apt源

Ubuntu 放弃了apt-key的GPG 密钥的管理方法,用户可以直接添加gpg密钥到/etc/apt/trusted.gpg.d/目录下。

同时添加删除apt source 直接在/etc/apt/sources.list.d/目录下操作即可。

1、删除旧的镜像源

bash 复制代码
#旧版操作方法
apt-key list # 列出许可证,在/trusted.gpg.d/中的是列不出来的
sudo apt-key del 0EBFCD88 # 根据编号删除gpg密钥
sudo rm /etc/apt/sources.list.d/docker.list #删除之前的源
sudo apt-get update # 更新apt 目录index

#新版方法
ls /etc/apt/trusted.gpg.d/
sudo rm /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
sudo rm /etc/apt/sources.list.d/docker.list
sudo apt-get update

2、添加阿里云docker apt源

bash 复制代码
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

#将 GPG 密钥存储在 /usr/share/keyrings/ 目录下,而不是 /etc/apt/trusted.gpg.d/ 目录下,这是因为新的推荐方法是使用 signed-by 选项将特定的密钥与特定的存储库关联起来。这种方法比将所有密钥存储在 /etc/apt/trusted.gpg.d/ 目录下更安全,因为它减少了一个密钥对多个存储库的信任范围。
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

ansible-playbook方式实现

yaml 复制代码
        # 任务2:添加 Docker 的 GPG 密钥
        # state: present # apt 模块会检查指定的软件包是否已经安装,如果尚未安装,则会安装它,如果已经安装,则>不会进行任何操作
        - name: Add Docker GPG key
          apt_key:
            url: https://download.docker.com/linux/ubuntu/gpg
            state: present

        # 任务3:添加 Docker 软件包源
        - name: Add Docker repository
          apt_repository:
            repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
            state: present
yaml 复制代码
---
- name: Setup Docker and Kubernetes Repositories from Aliyun
  hosts: localhost
  become: yes

  tasks:
    - name: Add Docker GPG key from Aliyun
      ansible.builtin.get_url:
        url: https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg
        dest: /usr/share/keyrings/docker-archive-keyring.gpg

    - name: Add Docker repository from Aliyun
      ansible.builtin.apt_repository:
        repo: "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu {{ ansible_distribution_release }} stable"
        state: present
        filename: docker

    - name: Add Kubernetes GPG key from Aliyun
      ansible.builtin.get_url:
        url: https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
        dest: /usr/share/keyrings/kubernetes-archive-keyring.gpg

    - name: Add Kubernetes repository from Aliyun
      ansible.builtin.apt_repository:
        repo: "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"
        state: present
        filename: kubernetes

    - name: Update apt cache
      ansible.builtin.apt:
        update_cache: yes
相关推荐
Rabbit_QL10 小时前
【网络设置】Docker 自定义网络深度解析:从踩坑到工程实践
网络·docker·容器
计算机小手13 小时前
使用 Poste.io 自建邮件服务器,Docker一键快速部署
经验分享·docker
warton8815 小时前
ubuntu24 安装 proxsql 实现数据库代理
linux·运维·mysql·ubuntu
天意pt15 小时前
Blog-SSR 系统操作手册(v1.0.0)
前端·vue.js·redis·mysql·docker·node.js·express
会跑的葫芦怪15 小时前
cursor 打开wsl Ubuntu项目
linux·运维·ubuntu
沫离痕16 小时前
windows安装docker实例
windows·docker·容器
ChenYY~16 小时前
双系统显卡冲突修复记录
ubuntu·显卡·黑屏·双系统·nvidia驱动
oMcLin16 小时前
如何在 Ubuntu 22.04 LTS 上部署并优化 OpenStack 云计算平台,实现多租户虚拟化与弹性伸缩?
ubuntu·云计算·openstack
majingming12317 小时前
ubuntu下的交叉编译
linux·运维·ubuntu
shchojj17 小时前
ubuntu 因为写错pam.d文件引起的sudo权限丢失
linux·运维·ubuntu