Centos7安装Docker

目前在做分布式开发,需要用到Docker,参考了书籍和网上教程,发现指令或者参数已经不能正常执行,所以在此记录下自己的安装过程,过程参照Docker官网

卸载旧版本

安装前,为了避免之前已经安装过产生冲突,卸载下之前的版本。

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

安装方式

你可以根据你的实际需要选取下面的安装方式:

  1. 设置Docker的yum,使用yum进行安装、升级等(推荐
  2. 使用rpm
  3. 使用自动自动安装脚本

本文仅介绍第一种yum安装方式进行安装。

开始YUM安装

注意:以下指令执行环境为Centos7,其它环境请前往官网进行查看。

  1. 设置仓库
    安装yum配置工具‘yum-utils’

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

    使用yum配置工具,添加docker的yum源

    	[root@instance-uzji0e5n ~]# yum-config-manager \
        >     --add-repo \
        >     https://download.docker.com/linux/centos/docker-ce.repo
        Loaded plugins: langpacks, versionlock
    	Repository epel is listed more than once in the configuration
    	Repository epel-debuginfo is listed more than once in the configuration
    	Repository epel-source is listed more than once in the configuration
    	adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    	grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    	Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 14] curl#6 - "Could not resolve host: download.docker.com; Unknown error"
    

    无法解析到download.docker.com,修改下本地的DNS,添加8.8.8.8,该DNS为Google提供,访问外网好用;若是国内,建议配置114.114.114.114。

    	[root@instance-uzji0e5n ~]# vi /etc/resolv.conf 
    	# Generated by NetworkManager
    	nameserver 192.168.0.3
    	nameserver 192.168.0.2
    	nameserver 8.8.8.8
    	options rotate timeout:1
    

    重新执行指令

    [root@instance-uzji0e5n ~]# yum-config-manager \
    >     --add-repo \
    >     https://download.docker.com/linux/centos/docker-ce.repo
    Loaded plugins: langpacks, versionlock
    Repository epel is listed more than once in the configuration
    Repository epel-debuginfo is listed more than once in the configuration
    Repository epel-source is listed more than once in the configuration
    adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
    grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
    repo saved to /etc/yum.repos.d/docker-ce.repo
    
    

    yum添加成功!

  2. 安装Docker-Engine 社区版

    $ sudo yum install docker-ce docker-ce-cli containerd.io
    

    若想安装指定版本docker-ce,可采用下面指令
    查询版本号

    $ sudo yum list docker-ce --showduplicates | sort -r
    

    安装指定版本号

    $ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
    
  3. 运行Docker-Engine

    $ sudo systemctl start docker
    
  4. 验证Docker-Engine

    $ sudo docker run hello-world
    

    这将会下载一个测试镜像,并在容器中运行,当该镜像容器开始运行的时候,将会打印一条信息,证明测试成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值