Centos7 安装Docker

Centos7 安装Docker

Docker安装需要Linux内核最低为3.8,建议在3.10以上

  1. 查看内核信息
[root@node ~]# uname -a
Linux node 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  1. 更新Yum
yum update  #完整更新软件与内核,在生产环境下慎用
  1. 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
  1. 设置yum源(选择其中一个)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库,推荐)
  1. 可以查看所有仓库中所有docker版本,并选择特定版本安装
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
 * updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
  1. 安装Docker,命令:yum install docker-ce-版本号
yum -y install docker-ce-18.03.1.ce

相关命令使用

服务相关

docker version   #查看版本
systemctl start docker   #启动Docker
systemctl stop docker    #关闭Docker
systemctl enable  docker   #设置开机自启动
systemctl disable  docker  #关闭开机自启动

Docker相关

docker ps   #查看当前正在运行的容器
ocker ps -a #查看所有容器的状态
docker images #查看本地镜像
原文地址:https://www.cnblogs.com/cuianbing/p/13209462.html