docker 容器里面是Ubuntu 9.4.0-1ubuntu1~20.04.1。
然后 apt update会报The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C。
然后去添加key,apt-key adv --recv-keys --keyserver keyserver.Ubuntu.com 871920D1991BC93C,会报E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation。
然后安装gnupg会提示缺少key,死循环了,该怎么办
解决方案:
这个问题很可能是由于容器内部的apt源配置有误导致的。下面是针对这个问题的解决方案:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
使用i键进入编辑模式,将文件中的内容全部替换成如下内容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
保存并退出编辑模式,使用:wq命令保存并退出文件。
sudo apt-get update
如果提示更新失败的话,可以重新执行一次apt-get update命令即可。如果依旧存在问题,可以尝试使用以下命令清理apt缓存:
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
现在可以安装gnupg了,使用以下命令即可:
sudo apt-get install gnupg
添加公钥:
sudo apt-key adv --recv-keys --keyserver keyserver.Ubuntu.com 871920D1991BC93C
现在再执行apt update应该就不会报错了。
如果需要恢复原来的apt源配置文件,可以使用以下命令:
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
好了,这个问题就结束了。