- 卸载历史版本冲突的配置信息
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
- Install using the
apt
repository, Set up Docker'sapt
repository.
# 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
- Install the Docker packages.To install the latest version, run
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:27.4.0-1~ubuntu.24.04~noble 5:27.3.1-1~ubuntu.24.04~noble ...
VERSION_STRING=5:27.4.0-1~ubuntu.24.04~noble sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
- 验证安装结果
sudo docker run hello-world
- 设置开机启动
sudo systemctl enable docker
- 设置工作目录,配置镜像加速
touch /etc/docker/daemon.json
{ "data-root": "/mnt/mydisk/docker", "registry-mirrors": ["https://mo4x3llw.mirror.aliyuncs.com"] }
加载配置
sudo systemctl daemon-reload
sudo systemctl restart docker