docker应用

docker安装

2026-06-20 #docker安装

Ubuntu Docker 安装(Markdown 版本)

来源:https://www.runoob.com/docker/ubuntu-docker-install.html

Ubuntu Docker 安装

Docker Engine-Community 支持以下的 Ubuntu 版本:

  • Xenial 16.04 (LTS)
  • Bionic 18.04 (LTS)
  • Cosmic 18.10
  • Disco 19.04
  • 其他更新的版本……

Docker Engine - Community 支持 x86_64(或 amd64)、armhf、arm64、s390x(IBM Z)和 ppc64le(IBM Power)架构。


使用官方安装脚本自动安装

安装命令如下:

1
2
3
4
5
6
7
8
9
10
# 下载并执行 Docker 官方安装脚本
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# 启动 Docker 服务
sudo systemctl start docker
sudo systemctl enable docker

# 安装docker-compose
apt-get install -y docker.io docker-compose

手动安装

卸载旧版本

Docker 的旧版本被称为 dockerdocker.iodocker-engine。如果已安装,请卸载它们:

1
sudo apt-get remove docker docker-engine docker.io containerd runc

当前称为 Docker Engine-Community 的软件包是 docker-ce

使用 Docker 仓库进行安装

在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后可以从仓库安装和更新 Docker。

设置仓库

  1. 更新 apt 包索引:
1
sudo apt-get update
  1. 安装 apt 依赖包(用于通过 HTTPS 获取仓库):
1
2
3
4
5
6
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
  1. 添加 Docker 的官方 GPG 密钥:
1
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  1. 设置稳定版仓库:
1
2
3
4
5
6
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

安装 Docker Engine-Community

  1. 更新 apt 包索引:
1
sudo apt-get update
  1. 安装最新版本:
1
sudo apt-get install docker-ce docker-ce-cli containerd.io

安装特定版本示例:

1
2
3
4
5
# 先查看可用版本
apt-cache madison docker-ce

# 安装指定版本
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

测试 Docker 安装

1
sudo docker run hello-world

成功后会输出 “Hello from Docker!” 等信息。


使用 Shell 脚本进行安装(备选)

1
2
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

非 root 用户使用

1
sudo usermod -aG docker your-user

卸载 Docker

1
2
3
4
5
# 删除安装包
sudo apt-get purge docker-ce

# 删除镜像、容器、配置文件等
sudo rm -rf /var/lib/docker

评论
分享