参考docker官方文档:https://docs.docker.com/engine/install/debian/
文章最后列出了使用国内源的安装步骤
卸载老版本:
老版本的Docker名为: docker, docker.io或者docker-engine(不存在)
$ sudo apt-get remove docker docker.io containerd runc
使用仓库安装
在安装Docker之前首先需要设置仓库源。
设置仓库源
- 更新apt包索引,并且安装https的依赖
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
- 添加Docker官方的 GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 使用下面的命令设置stable源
$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
lsb_release -cs 命令返回Debian的版本名
安装Docker
- 更新包索引并且安装最新版的docker
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- 安装指定版本
查看当前源中可用的版本:
$ apt-cache madison docker-ce
docker-ce | 5:20.10.8~3-0~debian-bullseye | https://mirrors.ustc.edu.cn/docker-ce/linux/debian bullseye/stable amd64 Packages
docker-ce | 5:20.10.7~3-0~debian-bullseye | https://mirrors.ustc.edu.cn/docker-ce/linux/debian bullseye/stable amd64 Packages
docker-ce | 5:20.10.6~3-0~debian-bullseye | https://mirrors.ustc.edu.cn/docker-ce/linux/debian bullseye/stable amd64 Packages
5:20.10.8~3-0~debian-bullseye
为版本号
安装指定版本
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
- 验证是否安装成功, 使用
hello-world
镜像验证
$ sudo docker run hello-world
使用国内源
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
$ curl -fsSL http://mirrors.ustc.edu.cn/docker-ce/linux/debian/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] http://mirrors.ustc.edu.cn/docker-ce/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null