Fix docker-ce GPG error in apt update on ubuntu

2024-06-22 / Ubuntu Docker Debian

Problem shown as in $ sudo apt update

$ sudo apt update
Hit:1 https://mirrors.ustc.edu.cn/ubuntu focal InRelease
Hit:2 https://mirrors.ustc.edu.cn/ubuntu focal-updates InRelease
Hit:3 https://mirrors.ustc.edu.cn/ubuntu focal-backports InRelease
Hit:4 https://mirrors.ustc.edu.cn/ubuntu focal-security InRelease
Get:5 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
Ign:5 https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal InRelease
Hit:8 https://esm.ubuntu.com/apps/ubuntu focal-apps-security InRelease
Hit:9 https://esm.ubuntu.com/apps/ubuntu focal-apps-updates InRelease
Hit:10 https://esm.ubuntu.com/infra/ubuntu focal-infra-security InRelease
Hit:11 https://esm.ubuntu.com/infra/ubuntu focal-infra-updates InRelease
Fetched 57.7 kB in 2s (24.4 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: GPG error: https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8

Solve with:

$ sudo mkdir -p /etc/apt/keyrings
$ sudo curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg

Edit /etc/apt/sources.list.d/docker.list as:

deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal stable