E: 列表文件 /etc/apt/sources.list.d/docker.list(组件)中格式错误的条目 1

E: Malformed entry 1 in list file /etc/apt/sources.list.d/docker.list (Component)

我开始了新的 class 并且我是新手 Linux。我使用 debian,并按照教师指南安装 git 和 docker。我在终端中输入了所有命令,直到出现错误。

  1. sudo apt install git 有效

git config --global user.name "Ion Popescu"
git config --global user.email "ion.popescu@gmail.com"
git config --global core.editor vim
git config --global core.pager more
git config --global help.autocorrect true 

一切正常

  1. sudo apt-get -y remove docker docker-engine docker.io 有效

sudo apt update
sudo apt install -y apt-transport-https ca-certificates wget
sudo apt install -y software-properties-common ssh

他们都工作了

5.

wget https://download.docker.com/linux/debian/gpg
sudo apt-key add gpg

工作

  1. echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list 有效

现在我必须输入这些行,但在第一行之后出现错误

7.

sudo apt update
sudo apt-cache policy docker-ce
sudo apt -y install docker-ce

E:列表文件 /etc/apt/sources.list.d/docker.list(组件)中格式错误的条目 1 E: 无法读取来源列表。

如何解决?

要确保 /etc/apt/sources.list.d/docker.list 的格式正确,请使用以下命令(tee 无需 -a 覆盖源):

在 debian Buster 上:

printf "%s\n" "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" |\
sudo tee /etc/apt/sources.list.d/docker.list

在 debian Stretch 上:

printf "%s\n" "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" |\
sudo tee /etc/apt/sources.list.d/docker.list

(您可以使用 $(lsb_release -cs) 而不是需要安装 lsb-release 软件包的 debian 代号。)

另一种添加 docker-ce 存储库的方法:您已经安装了 software-properties-common,您可以使用 add-apt-repository 添加存储库:

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"

Docker-ce docs

试试这个,它对我有用:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null`

问题在于变量 $(lsb_release -cs),在 linux 中它 returns 类似于 una(至少在 Mint 20.3 上)。我认为没有专门的 mint 存储库,因此您必须对其进行硬编码。我在关注官方文档,但也阅读了 this forum,其中提到您还需要删除 /etc/apt/sources.listd/docker.list.

中可用的当前 docker 列表