美文网首页
Centos7安装Docker

Centos7安装Docker

作者: hsyman | 来源:发表于2020-12-16 11:15 被阅读0次

    通用安装方式

    Docker 软件包已经包括在默认的 CentOS-Extras 软件源(联网使用centos7u2自带网络Yum源)里。因此想要安装 docker,只需要运行下面的 yum 命令:
    yum -y install docker

    启动 Docker 服务:
    CentOS 7
    systemctl start docker.service
    systemctl enable docker.service

    确定docker服务在运行
    结果会显示服务端和客户端的版本,如果只显示客户端版本说明服务没有启动
    docker version

    Client:
    Version:         1.10.3
    API version:     1.22
    Package version: docker-common-1.10.3-46.el7.centos.14.x86_64
    Go version:      go1.6.3
    Git commit:      cb079f6-unsupported
    Built:           Fri Sep 16 13:24:25 2016
    OS/Arch:         linux/amd64
    
    Server:
    Version:         1.10.3
    API version:     1.22
    Package version: docker-common-1.10.3-46.el7.centos.14.x86_64
    Go version:      go1.6.3
    Git commit:      cb079f6-unsupported
    Built:           Fri Sep 16 13:24:25 2016
    OS/Arch:         linux/amd64
    

    查看docker基本信息:
    docker info

    校验Docker的安装
    docker run -it ubuntu bash

    Unable to find image 'ubuntu:latest' locally
    Trying to pull repository daocloud.io/ubuntu ... 
    latest: Pulling from daocloud.io/ubuntu
    22ecafbbcc4a: Pull complete 
    580435e0a086: Pull complete 
    Digest: sha256:80c2902178d79f439b13c5a244f3b1ef67ca890dbbe58d19caa13301ca56a505
    

    国内源安装

    阿里源:https://mirrors.aliyun.com
    删除已安装的Docker
    yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
    配置阿里云Docker Yum源
    yum install -y yum-utils device-mapper-persistent-data lvm2 git
    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

    安装指定版本
    查看Docker版本
    yum list docker-ce --showduplicates
    安装较旧版本(比如Docker 17.03.2)
    需要指定完整的rpm包的包名,并且加上--setopt=obsoletes=0 参数
    yum install -y --setopt=obsoletes=0 docker-ce-17.03.2.ce-1.el7.centos.x86_64 docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch

    安装Docker新版本(比如Docker 19.0.3)
    加上rpm包名的版本号部分或不加都可以:
    yum install docker-ce-19.0.3.ce -y
    yum install docker-ce -y

    启动Docker服务
    systemctl enable docker
    systemctl start docker

    查看Docker版本状态
    docker -v

    Docker version 19.03.8, build afacb8b
    

    docker version

    Client: Docker Engine - Community
         Version:           19.03.8
         API version:       1.40
         Go version:        go1.12.17
         Git commit:        afacb8b
         Built:             Wed Mar 11 01:27:04 2020
         OS/Arch:           linux/amd64
         Experimental:      false
    
        Server: Docker Engine - Community
         Engine:
          Version:          19.03.8
          API version:      1.40 (minimum version 1.12)
          Go version:       go1.12.17
          Git commit:       afacb8b
          Built:            Wed Mar 11 01:25:42 2020
          OS/Arch:          linux/amd64
          Experimental:     false
         containerd:
          Version:          1.2.13
          GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
         runc:
          Version:          1.0.0-rc10
          GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
         docker-init:
          Version:          0.18.0
          GitCommit:        fec3683
    

    查看docker运行状态
    docker info

    Client:
            Debug Mode: false
        Server:
         Containers: 0
          Running: 0
          Paused: 0
          Stopped: 0
         Images: 0
         Server Version: 19.03.8
         Storage Driver: overlay2
          Backing Filesystem: <unknown>
          Supports d_type: true
          Native Overlay Diff: true
         Logging Driver: json-file
         Cgroup Driver: cgroupfs
         Plugins:
          Volume: local
          Network: bridge host ipvlan macvlan null overlay
          Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
         Swarm: inactive
         Runtimes: runc
         Default Runtime: runc
         Init Binary: docker-init
         containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
         runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
         init version: fec3683
         Security Options:
          seccomp
           Profile: default
         Kernel Version: 3.10.0-1062.18.1.el7.x86_64
         Operating System: CentOS Linux 7 (Core)
         OSType: linux
         Architecture: x86_64
         CPUs: 2
         Total Memory: 3.84GiB
         Name: HSY
         ID: KX4W:ZAV4:W3I6:ZPIJ:ZFFP:P3S3:5PNS:3C4L:WBDR:RPXJ:R6SE:FREH
         Docker Root Dir: /var/lib/docker
         Debug Mode: false
         Registry: https://index.docker.io/v1/
         Labels:
         Experimental: false
         Insecure Registries:
          127.0.0.0/8
         Live Restore Enabled: false
    

    报错解决

    docker info的时候报如下错误

    bridge-nf-call-iptables is disabled
    

    追加如下配置,然后重启系统
    vim /etc/sysctl.conf

    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.bridge.bridge-nf-call-arptables = 1
    

    相关文章

      网友评论

          本文标题:Centos7安装Docker

          本文链接:https://www.haomeiwen.com/subject/ghengktx.html