目前在做分布式开发,需要用到Docker,参考了书籍和网上教程,发现指令或者参数已经不能正常执行,所以在此记录下自己的安装过程,过程参照Docker官网
卸载旧版本
安装前,为了避免之前已经安装过产生冲突,卸载下之前的版本。
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装方式
你可以根据你的实际需要选取下面的安装方式:
本文仅介绍第一种yum安装方式进行安装。
开始YUM安装
注意:以下指令执行环境为Centos7,其它环境请前往官网进行查看。
-
设置仓库
安装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添加成功!
-
安装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
-
运行Docker-Engine
$ sudo systemctl start docker
-
验证Docker-Engine
$ sudo docker run hello-world
这将会下载一个测试镜像,并在容器中运行,当该镜像容器开始运行的时候,将会打印一条信息,证明测试成功。