栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux(centos)环境安装、卸载docker

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux(centos)环境安装、卸载docker

目录

1.检查环境和依赖

        1.检查系统内核,需要3.10以上版本

        2.检查centos版本,需要centos7以上 

        3.安装依赖

        4.设置yum源

2.安装程序包

3.卸载docker

        1.查询docker安装的包

        2.卸载依赖

        3.删除文件


1.检查环境和依赖

        1.检查系统内核,需要3.10以上版本
[root@bd ~]# uname -r
3.10.0-1160.el7.x86_64

        2.检查centos版本,需要centos7以上 
[root@bd ~]# cat /etc/redhat-release 

CentOS Linux release 7.9.2009 (Core)

        或者

[root@bd ~]# cat /etc/os-release 

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

        3.安装依赖

        yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

        4.设置yum源

设置源官方镜像

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

 这里设置的是国内阿里云的镜像

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#提示如下
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

2.安装程序包

如果有安装过docker,先卸载

yum remove docker 
           docker-client 
           docker-client-latest 
	       docker-common 
	       docker-latest 
	       docker-latest-logrotate 
	       docker-logrotate 
	       docker-engine

可以查看所有仓库中所有docker版本,并选择特定版本安装:

//列出可用源
yum list docker-ce --showduplicates | sort -r

//根据列出的版本选择某一版本
yum install -y docker-ce-*** docker-ce-cli-*** containerd.io

我这里选择直接安装最新版

[root@bd ~]# yum install -y docker-ce docker-ce-cli containerd.io

提示已安装成功 

启动并设置开机自启动

 //启动docker
systemctl start docker
 //设置开机自启动
systemctl enable docker

查看docker版本,有client和server信息代表启动成功

[root@bd ~]# docker version

Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:41 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:44:05 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

通过 systemctl status docker 查看docker状态

[root@bd ~]# systemctl status docker

● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since 二 2021-12-28 11:12:56 CST; 3min 7s ago
     Docs: https://docs.docker.com
 Main PID: 13996 (dockerd)
    Tasks: 49
   Memory: 48.7M
   CGroup: /system.slice/docker.service
           └─13996 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

3.卸载docker

        1.查询docker安装的包
[root@bd ~]# yum list installed | grep docker
containerd.io.x86_64                   1.4.12-3.1.el7                  @docker-ce-stable
docker-ce.x86_64                       3:20.10.12-3.el7                @docker-ce-stable
docker-ce-cli.x86_64                   1:20.10.12-3.el7                @docker-ce-stable
docker-ce-rootless-extras.x86_64       20.10.12-3.el7                  @docker-ce-stable
docker-scan-plugin.x86_64              0.12.0-3.el7                    @docker-ce-stable

        2.卸载依赖
yum remove docker-ce docker-ce-cli containerd.io

        3.删除文件
rm -rf /var/lib/docker

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/679874.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号