在Redhat/CentOS上安装Docker

一、系统要求
1)和你系统的版本要匹配
2)centos-extras repository 必须启用,这个库默认是启用的,但是如果你关掉了它,你必须重新启用。
3)推荐使用overlay2 存储协议。

二、卸载旧版本
如果你没有安装旧版本,就不必卸载了。
之前的旧版本叫做 docker 或者 docker-engine,如何安装了这俩,那就先卸载,包括相关的依赖。

$ 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

如果没有安装这地方也会报没有安装这些包的信息。
在Redhat/CentOS上安装Docker_第1张图片
上图代表没有安装。

三、安装Docker CE
有三种方式可以安装 Docker CE,具体选择哪一种方式取决于你的需要:
方法一:先安装docker源 然后基于这个源来安装。这是比较推荐的做法,这样便于安装和升级。
方法二:下载 docker 的RPM包,然后手动安装,并且完全手动管理和升级,这种方式适合安装的主机无法接入互联网的情况。
方法三:在测试开发环境中,也可以用自动化脚本进行简易安装。

下面逐一介绍(主要是方法一):
方法一:
在你第一次安装docker或者在一个新机器上安装docker之前,你必须先安装docker的源,然后你才可以从这个源上安装并且更新docker。
1、 安装docker源
1)安装需要的yum功能包 yum-utils用于支持yum-config-manager(yum配置管理器)功能,
device-mapper-persistent-data和lvm2用户支持devicemapper存储驱动。
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

在Redhat/CentOS上安装Docker_第2张图片

2)增加稳定的docker源,尽管edge或者test的源也可以,但是还是有稳定的比较好。
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
在Redhat/CentOS上安装Docker_第3张图片

3)可选项:启动edge和test源,这些源里面含有docker.repo文件,但默认是关闭的,你也可以启用他们。
$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test
You can disable the edge or test repository by running the  yum-config-manager command with the  --disable flag. To re-enable it, use the  --enable flag. The following command disables the edge repository.
$ sudo yum-config-manager --disable docker-ce-edge
Note: Starting with Docker 17.06, stable releases are also pushed to the edge and testrepositories.
Learn about stable and edge builds.

2、安装Docker CE

1)安装最新版本的docker ce
$ sudo yum install docker-ce


No package docker available
yum没有找到docker-ce包,而docker-ce是第三方软件,更新epel第三方软件库,运行命令:

sudo yum install epel-release
在Redhat/CentOS上安装Docker_第4张图片

EPEL   (Extra Packages for Enterprise Lin ux)是基于Fe dora的一个项目,为“红帽系”的操作 系统提供额外的软件包 ,适用于RHEL、CentOS和Scientific Linux.

再次执行:

$ sudo yum install docker-ce

在Redhat/CentOS上安装Docker_第5张图片

还是没有 docker-ce 包!

安装老版本看看:
$ sudo yum install docker

安装结果:

在Redhat/CentOS上安装Docker_第6张图片

2)可选项:在你的生产系统内,你应该安装指定版本的docker ce而不是总是安装最新的
列出你的源中的所有可用版本,从最高到最低。
$ yum list docker-ce --showduplicates | sort -r

在Redhat/CentOS上安装Docker_第7张图片
列表里的内容是你源里面包含的版本,和你linux版本(el7后缀表示linux版本)也有关系。选择你要安装的版本,第二列为版本字符串。

The contents of the list depend upon which repositories are enabled, and are specific to your version of CentOS (indicated by the .el7 suffix on the version, in this example). Choose a specific version to install. The second column is the version string. You can use the entire version string, but you need to include at least to the first hyphen. The third column is the repository name, which indicates which repository the package is from and by extension its stability level. To install a specific version, append the version string to the package name and separate them by a hyphen (-).
Note: The version string is the package name plus the version up to the first hyphen. In the example above, the fully qualified package name is docker-ce-17.06.1.ce.

$ sudo yum install

3)启动docker

$ sudo systemctl start docker

报错。
查看状态:
$ systemctl status docker.service -l
加 -l 有的行信息很长,打印的时候会省略,加此参数则全部显示。

在Redhat/CentOS上安装Docker_第8张图片

报错信息:
Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docker (--selinux-enabled=false)
意思是说, 此linux的内核中的SELinux不支持 overlay2 graph driver ,解决方法有两个,要么启动一个新内核,要么就在docker里禁用selinux,--selinux-enabled=false
重新编辑docker配置文件:
vi /etc/sysconfig/docker

在Redhat/CentOS上安装Docker_第9张图片
改为:
在Redhat/CentOS上安装Docker_第10张图片

重启docker:



查看状态:
$ systemctl status docker.service -l
在Redhat/CentOS上安装Docker_第11张图片
搞定!!

4)验证安装是否成功
通过运行hello-world镜像来验证安装是否成功。
$ sudo docker run hello-world
在Redhat/CentOS上安装Docker_第12张图片
确实成功了,oye!

方法二:
1)登陆  https://download.docker.com/linux/centos/7/x86_64/stable/Packages/  下载你所需要的 .rpm 文件。
2)安装你下载的文件
$ sudo yum install /path/to/package.rpm 3)启动 Docker.
$ sudo systemctl start docker4)验证安装是否成功
sudo docker run hello-world

方法三:
$ curl -fsSL get.docker.com -o get-docker.sh $ sudo sh get-docker.sh


四、卸载docker
1)卸载安装包
$ sudo yum remove docker-ce
2)删除文件
$ sudo rm -rf /var/lib/docker

详情参见docker官方网址:

https://docs.docker.com/install/linux/docker-ce/centos/

你可能感兴趣的:(在Redhat/CentOS上安装Docker)