Skip to main content

安装或卸载 Docker

· 2 min read
Alan

安装或者卸载Docker.

CentOS 安装

参考: How to Upgrade Docker on CentOS

# 如果系统上已经安装, 先卸载 Docker
# yum remove docker docker-common docker-selinux docker-engine

# Install required packages
yum install -y yum-utils device-mapper-persistent-data lvm2
# Use the following command to set up the stable repository
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 增加仓库
# Install the latest version of Docker CE and containerd
yum install docker-ce docker-ce-cli containerd.io -y

Ubuntu 安装

# 如果你过去安装过 docker,先删掉
# apt-get remove docker docker-engine docker.io

# Update the apt package index
apt-get update

# Install packages to allow apt to use a repository over HTTPS
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y

# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88

# Set up the stable repository
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update

# install
apt-get install docker-ce docker-ce-cli containerd.io -y

清华大学开源镜像

参考 Docker Community Edition 镜像使用帮助

CentOS

# 如果你之前安装过 docker,请先删掉
yum remove docker docker-common docker-selinux docker-engine

# 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2 wget

# 下载repo文件
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

# 把软件仓库地址替换为 TUNA:
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

# 安装
yum makecache fast
yum install docker-ce

Ubuntu

# 如果你过去安装过 docker,先删掉
# apt-get remove docker docker-engine docker.io

# 安装依赖
apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

# 信任 Docker 的 GPG 公钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 对于 amd64 架构的计算机,添加软件仓库
add-apt-repository \
"deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"

# 如果你是树莓派或其它 ARM 架构计算机,请运行:
echo "deb [arch=armhf] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list

# 安装
apt-get update
apt-get install docker-ce