因为想要在LXC的虚拟机上安装docker,所以查了一些资料,但是后来发现我的这个虚拟机不支持docker,即使安装之后也无法启动,不过通过这次安装也查了一些资料,发现网上找的许多东西都不太对,最保险的方法还是通过官网的方法来,最后也是使用官网的方法在另外一个虚拟机上安装成功的,所以整理一下过程。
准备Prerequisites
系统需求OS requirements
To install Docker Engine, you need the 64-bit version of one of these Debian or Raspbian versions:
- Debian Bullseye 11 (stable)
- Debian Buster 10 (oldstable)
- Raspbian Bullseye 11 (stable)
- Raspbian Buster 10 (oldstable)
Docker Engine is compatible with x86_64 (or amd64), armhf, and arm64 architectures.
卸载旧版本Uninstall old versions
Older versions of Docker went by the names of docker, docker.io, or docker-engine. Uninstall any such older versions before attempting to install a new version:
sudo apt-get remove docker docker-engine docker.io containerd runc
我当时折腾的时候显示没有containerd,安装的是containerd.io,想来是因为我安装的不是旧版本吧。
It’s OK if apt-get reports that none of these packages are installed.
Images, containers, volumes, and networks stored in /var/lib/docker/ aren’t automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, refer to the uninstall Docker Engine section.
也就是说,如果你需要删除之前下载的images等,需要参考uninstall Docker Engine section。
安装方法Installation methods
一共有三种安装方法,分别是存储库安装、手动安装和脚本安装,在这里我只使用了库安装的方法。
使用库安装Install using the repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
设置Docker库Set up the repository
Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-releaseAdd Docker’s official GPG key:
在这里许多教程都少了新建文件夹这一步:sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgUse the following command to set up the repository:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装Docker Install Docker Engine
This procedure works for Debian on x86_64 (or amd64), armhf, and arm64 architectures, and Raspbian.
Update the apt package index:
sudo apt-get update
如果这一步GPG出错的话,运行一下命令:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
Install Docker Engine, containerd, and Docker Compose.
To install the latest version, run:sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
To install a specific version of Docker Engine, start by list the available versions in the repository:
# List the available versions:
apt-cache madison docker-ce | awk '{ print $3 }'
5:18.09.1~3-0~debian-stretch
5:18.09.0~3-0~debian-stretch
18.06.1~ce~3-0~debian
18.06.0~ce~3-0~debianSelect the desired version and install:
VERSION_STRING=5:18.09.0~3-0~debian-stretch
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-compose-pluginVerify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
到此Docker的安装就完成了,后面还有一些如何更新以及其他的安装方法,就不做过多介绍了,发现脚本安装也很方便,最后再说一下Docker的卸载。
卸载Docker Uninstall Docker Engine
Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras
竟然发现了卸载方法,立马把之前LXC的虚拟机里无法运行的Docker卸载,倒是真的能清理出不少空间,但是还是无法恢复到安装前的状态,free 分别为1xx MB?到247 MB和290 MB到382 MB。
Images, containers, volumes, or custom configuration files on your host aren’t automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
现在终于释放出大部分空间了,free分别为783 MB和803 MB。
You must delete any edited configuration files manually.
所以配置文件存在哪?



