Linux 安装 Docker CE

目录

前言

Docker是一种轻量级的虚拟化技术,同时是一个开源的应用容器运行环境搭建平台,可以让开发者以便捷方式打包应用到一个可移植的容器中,然后安装至任何运行Linux或Windows等系统的服务器上。相较于传统虚拟机,Docker容器提供轻量化的虚拟化方式、安装便捷、启停速度快。

Ubuntu 安装 Docker CE

系统需求

  • Ubuntu Questing 25.10
  • Ubuntu Noble 24.04 (LTS)
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)

适用于 Ubuntu 的 Docker Engine 兼容 x86_64(或 amd64)、armhf、arm64、s390x 及 ppc64le(ppc64el)架构。

卸载旧版本

				
					sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
				
			

使用 apt repository 安装

配置 Docker CE apt repository

				
					# Add Docker's official GPG key:
sudo apt update
sudo apt 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:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
				
			

安装 Docker CE

				
					sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
				
			

安装 Docker CE 特定版本

				
					apt list --all-versions docker-ce

VERSION_STRING=5:29.2.1-1~ubuntu.24.04~noble

sudo apt install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
				
			

运行 Docker CE 并配置开机自动运行

				
					sudo systemctl enable docker --now

# 查看Docker运行状态
sudo systemctl status docker
				
			

Debian 安装 Docker CE

系统需求

  • Debian Trixie 13 (stable)
  • Debian Bookworm 12 (oldstable)
  • Debian Bullseye 11 (oldoldstable)

适用于 Debian 的 Docker 引擎兼容 x86_64(或 amd64)、armhf(arm/v7)、arm64 以及 ppc64le(ppc64el)架构。

卸载旧版本

				
					sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-doc podman-docker containerd runc | cut -f1)
				
			

使用 apt repository 安装

配置 Docker CE apt repository

				
					# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
				
			

安装 Docker CE

				
					sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
				
			

安装 Docker CE 特定版本

				
					apt list --all-versions docker-ce

VERSION_STRING=5:29.2.1-1~debian.12~bookworm

sudo apt install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
				
			

运行 Docker CE 并配置开机自动运行

				
					sudo systemctl enable docker --now

# 查看Docker运行状态
sudo systemctl status docker
				
			

CentOS 安装 Docker CE

系统需求

  • CentOS Stream 10
  • CentOS Stream 9

必须启用 centos-extras 软件仓库。该仓库默认处于启用状态。若您曾将其禁用,则需重新启用。

卸载旧版本

				
					sudo dnf remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
				
			

使用 rpm repository 安装

配置 Repository

				
					sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
				
			

安装 Docker CE

				
					sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
				
			

安装 Docker CE 特定版本

				
					dnf list docker-ce --showduplicates | sort -r

# 将<VERSION_STRING>替换为所需版本号,然后运行以下命令进行安装
sudo dnf install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin
				
			

运行 Docker CE 并配置开机自动运行

				
					sudo systemctl enable docker --now

# 查看Docker运行状态
sudo systemctl status docker
				
			

更多资料请参考以下链接:https://docs.docker.com/engine/install/

发表评论须遵守中华人民共和国相关法律法规。违规评论将会被删除。

Comments must subject to the relevant laws and regulations of the People’s Republic of China. Offending comments will be deleted.

订阅评论
提醒
guest

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

0 评论
最新
最旧
内联反馈
查看所有评论
滚动到顶部