使用apt仓库安装
1. 设置apt仓库
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
2. 安装docker软件包
最新版
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
指定版本
# List the available versions:
apt-cache madison docker-ce | awk '{ print $3 }'
5:24.0.0-1~ubuntu.22.04~jammy
5:23.0.6-1~ubuntu.22.04~jammy
...
选择指定版本并且安装
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
3. 通过运行hello-word镜像来验证docker 引擎是否成功安装
sudo docker run hello-world
这个命令会下载测试镜像,并且运行一个容器。当容器运行时,它会打印确认信息然后退出。
从软件包安装
-
Go to Index of linux/ubuntu/dists/.
-
Select your Ubuntu version in the list.
-
Go to
pool/stable/
and select the applicable architecture (amd64
,armhf
,arm64
, ors390x
). -
Download the following
deb
files for the Docker Engine, CLI, containerd, and Docker Compose packages:containerd.io_<version>_<arch>.deb
docker-ce_<version>_<arch>.deb
docker-ce-cli_<version>_<arch>.deb
docker-buildx-plugin_<version>_<arch>.deb
docker-compose-plugin_<version>_<arch>.deb
-
Install the
.deb
packages. Update the paths in the following example to where you downloaded the Docker packages.$ sudo dpkg -i ./containerd.io_<version>_<arch>.deb \ ./docker-ce_<version>_<arch>.deb \ ./docker-ce-cli_<version>_<arch>.deb \ ./docker-buildx-plugin_<version>_<arch>.deb \ ./docker-compose-plugin_<version>_<arch>.deb
The Docker daemon starts automatically.
-
Verify that the Docker Engine installation is successful by running the
hello-world
image.$ sudo service docker start $ 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.
You have now successfully installed and started Docker Engine.
卸载Docker
-
Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
-
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