侧边栏壁纸

在CentOS中安装Docker

2018年09月29日 309阅读 0评论 0点赞


安装要求


  1. 本教程只教授CentOS Linux系统下Docker的安装
  2. Docker分为Docker CE与Docker EE,前者为社区免费版,后者为商业收费版。本教程安装的是Docker CE
  3. Docker支持以下版本的CentOS:

    • CentOS 7 (64-bit)
    • CentOS 6.5 (64-bit) 或更高的版本
  4. 目前,CentOS 仅发行版本中的内核支持 Docker

    • Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上
    • Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本

使用yum安装


确认系统版本

Docker 要求 CentOS 系统的内核版本高于 3.10 ,在终端中通过 uname -r 命令查看你当前的内核版本


移除旧版本

如果不确定当前系统是否安装了Docker则可以使用以下命令来执行检查并清理旧版本

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

安装必要工具

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

添加Docker软件源信息

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

更新yum缓存

$ sudo yum makecache fast

安装Docker CE

$ sudo yum -y install docker-ce

启动Docker后台服务

$ sudo systemctl start docker

测试运行

  1. 可以使用docker --version查看docker的版本
  2. 运行docker run hello-world来运行测试镜像,出现如下内容则安装成功

    Hello from Docker!
    This message shows that your installation appears to be working correctly.

    To generate this message, Docker took the following steps:

    1. The Docker client contacted the Docker daemon.
    2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
      (amd64)
    3. The Docker daemon created a new container from that image which runs the
      executable that produces the output you are currently reading.
    4. The Docker daemon streamed that output to the Docker client, which sent it
      to your terminal.

    To try something more ambitious, you can run an Ubuntu container with:
    $ docker run -it ubuntu bash

    Share images, automate workflows, and more with a free Docker ID:
    https://hub.docker.com/

    For more examples and ideas, visit:
    https://docs.docker.com/get-started/

使用脚本安装Docker


使用 sudo 或 root 权限登录 Centos

$ sudo -s
password:

更新yum,确保其为最新版本

$ sudo yum update

下载docker安装脚本并执行安装

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh


启动Docker进程

$ sudo systemctl start docker

测试安装

$ sudo docker run hello-world

镜像加速


鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们需要配置加速器来解决,我使用的是中科大的镜像源,具体配置方法请查看官方说明:http://mirrors.ustc.edu.cn/help/dockerhub.html


0
打赏

—— 评论区 ——

博主关闭了当前页面的评论
博主栏壁纸
16 文章数
29 标签数
10 评论量
人生倒计时
舔狗日记