Docker for CentOS安装教程

版权声明:一篇成长日记文章,没什么转载价值。 https://blog.csdn.net/zhaoyanga14/article/details/86568923

文档中颜色说明:

绿色:重要并需要执行。

红色:需要注意。

灰色:可能无关紧要。

 

CentOS安装Docker教程(不确定是否适用于其他系统)

 

Docker通常运行在CentOS 7上,因为Docker运行环境要求系统为64位、系统内核版本为3.8以上。

 

通过 uname -r 命令查看你当前的内核版本。

 

CentOS 6默认的Linux内核版本为2.6及以下,CentOS 7默认的Linux内核版本为3.10,因此,对于CentOS 6则需进行内核版本的升级。

而CentOS 7的话可以直接跟着官网或者教学网站上面的教程安装即可。这里提供一个网站:http://www.runoob.com/docker/centos-docker-install.html

 

下面是CentOS 6安装Docker的教程:

 

这是更新Linux内核的网址:http://elrepo.org/tiki/tiki-index.php

如果看不懂的话,就直接跟着我后面写的做就好。

 

一、升级内核

1)首先切换到root用户下,因为安装过程需要管理员权限:

su

会提示输入密码,输入root用户的密码即可。

(如果root用户没有密码,可以通过 sudo passwd root 指令来设置密码)

(输入 su "king" 或者 exit 可以回到之前的用户。)

 

2)导入public key

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

 

3)安装ELRepo

rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

 

4)安装kernel

长期支持的版本,稳定(推荐)

yum --enablerepo=elrepo-kernel install -y kernel-lt

 

主线版本(mainline)

yum --enablerepo=elrepo-kernel install -y kernel-ml

 

5)修改Grub引导顺序,设置默认启动新升级的内核。

1.编辑grub.conf文件:

运行 vi /etc/grub.conf 指令。

 

2.点击键盘上的字母 i 进入输入模式。

 

将 default 属性修改为新安装内核的位置。

下面是我的grub.conf文件的内容,可以看到 title CentOS (4.4.169... 这一个是我安装的新的内核,下面那个 title CentOS 6 (2.6.32... 是以前低版本的。所以要把 default 属性值设置为 0 ,代表默认启动第一个内核。

 

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title CentOS (4.4.169-1.el6.elrepo.x86_64)

        root (hd0,0)

        kernel /vmlinuz-4.4.169-1.el6.elrepo.x86_64 ro root=UUID=93dc4f5a-44fa-4a53-8943-dead6333465f rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

        initrd /initramfs-4.4.169-1.el6.elrepo.x86_64.img

title CentOS 6 (2.6.32-696.el6.x86_64)

        root (hd0,0)

        kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=93dc4f5a-44fa-4a53-8943-dead6333465f rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

        initrd /boot/initramfs-2.6.32-431.3.1.el6.x86_64.img

 

3.修改好之后,点击键盘 ESC 键。

4.输入 :wq 代表保存并退出。

5.回车。

 

6)重启以下系统,内核就升级完成了。

重启指令:reboot

 

二、安装Docker

1)禁用selinux(可以先不禁用,因为这里可能不会出现冲突情况,如果报错的话再尝试禁用)

因为selinux和LXC有冲突,所以禁用掉selinux。

同样是修改文件中的配置。

vi /etc/selinux/config

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing - SELinux security policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

 

2)配置Fedora EPEL源

 

由于CentOS 6与7安装Docker是有一些不同的,CentOS 6上Docker的安装包叫docker-io,来源于Fedora EPEL库,这个仓库维护了大量的没有包含在发行版中的软件,所以先要安装EPEL。而CentOS 7的Docker直接包含在官方镜像源的Extras仓库(并且阿里的仓库里也有)。

 

yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

 

3)安装Docker

yum install -y docker-io

 

4)启动Docker服务

service docker start

 

5)查看docker版本

docker version

 

Client version: 1.7.1

Client API version: 1.19

Go version (client): go1.4.2

Git commit (client): 786b29d/1.7.1

OS/Arch (client): linux/amd64

Server version: 1.7.1

Server API version: 1.19

Go version (server): go1.4.2

Git commit (server): 786b29d/1.7.1

OS/Arch (server): linux/amd64

 

6)执行docker hello-world

拉取 hello-world 镜像:

docker pull hello-world

 

执行 hello-world:

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.

    (Assuming it was not already locally available.)

 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

 

For more examples and ideas, visit:

 http://docs.docker.com/userguide/

 

*出现上面的输出信息表示Docker已经完全安装成功。

 

三、卸载Docker

 

如果要卸载Docker,需要先查看Docker安装包:

yum list installed | grep docker

 

然后删除安装包:

yum -y remove docker-io.x86_64

 

删除镜像或容器:

rm -rf /var/lib/docker

 

就可以了。

猜你喜欢

转载自blog.csdn.net/zhaoyanga14/article/details/86568923