CentOS7安装Docker Engine

DevOps 2020年06月04日

本篇笔记记录了在Linux的CentOS7发行版下,使用yum在线安装和rpm包离线安装Docker Engine的过程

yum在线安装

卸载旧版本

#查看已安装的包
yum list installed | grep docker
#卸载
yum remove 完整包名

设置Docker源

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装Docker

sudo yum install docker-ce docker-ce-cli

设置开机自启动

sudo systemctl daemon-reload
sudo systemctl enable docker

运行Docker

sudo systemctl start docker

查看运行状态

sudo systemctl status docker

测试Docker

sudo docker run hello-world

RPM包安装

卸载旧版本

#查看已安装包
sudo rpm  -qa | grep docker
#卸载
sudo rpm -e 完整包名

下载RPM包,docker-ce依赖containerd.io和docker-ce-cli,所以3个包都要下载

sudo wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
sudo wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.el7.x86_64.rpm
sudo wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm

安装Docker

sudo rpm -ivh containerd.io-1.2.6-3.3.el7.x86_64.rpm
sudo rpm -ivh docker-ce-cli-19.03.9-3.el7.x86_64.rpm
sudo rpm -ivh docker-ce-19.03.9-3.el7.x86_64.rpm

设置开机自启动

sudo systemctl daemon-reload
sudo systemctl enable docker

运行Docker

sudo systemctl start docker

查看运行状态

sudo systemctl status docker

测试Docker

sudo docker run hello-world