因爲docker要求運行的linux內核版本爲3.8以上,所以,在安裝以前,要查看一下宿主機操做系統的內核版本,不然若是是內核低於3.8,可以成功安裝docker,但進入docker後,會自動退出。php
一、下載安裝Centos 6.9linux
Centos 6 系列,最新版本爲6.9,因爲 docker 只能運行在64位系統上,所以到Centos的官網上選擇某個鏡像 下載 Centos 6.9 64位docker
二、升級Centos的linux內核ubuntu
Centos 6.9默認的linux內核版本爲2.6,Centos 7默認的linux內核版本爲3.10,所以,對於Centos 6.9則需進行內核版本的升級centos
1)進入更新linux內核的網址 http://elrepo.org/tiki/tiki-index.phpbash
2)按照操做指引進行內核更新,在root帳號下執行如下指令微信
(1)導入 public keyapp
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
(2)安裝ELRepoide
針對Centos6,大數據
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
針對Cenos7,
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm (external link)
(3)安裝kernel
長期支持的版本,穩定(推薦)
yum --enablerepo=elrepo-kernel install -y kernel-lt
主線版本(mainline)
yum --enablerepo=elrepo-kernel install -y kernel-ml
(4)修改Grub引導順序,設置默認啓動新升級的內核
編輯grub.conf文件
vi /etc/grub.conf
將 default 修改成新安裝內核的位置
# grub.conf generated by anaconda # default=0 #通常最新安裝的內核在第一個位置,將其修改成 0 timeout=5 splashimage=(hd0,0)/boot/grub/splash.xpm.gz hiddenmenu title CentOS (3.10.28-1.el6.elrepo.x86_64) root (hd0,0) kernel /boot/vmlinuz-3.10.28-1.el6.elrepo.x86_64 ro root=UUID=0a05411f-16f2-4d69-beb0-2db4cefd3613 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet initrd /boot/initramfs-3.10.28-1.el6.elrepo.x86_64.img title CentOS (2.6.32-431.3.1.el6.x86_64) root (hd0,0) kernel /boot/vmlinuz-2.6.32-431.3.1.el6.x86_64 ro root=UUID=0a05411f-16f2-4d69-beb0-2db4cefd3613 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet initrd /boot/initramfs-2.6.32-431.3.1.el6.x86_64.img
(5)重啓,內核升級完成
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.x與7.x安裝docker是有一些不一樣的,CentOS 6.x上docker的安裝包叫docker-io,來源於Fedora epel庫,這個倉庫維護了大量的沒有包含在發行版中的軟件,因此先要安裝EPEL,而CentOS 7.x的docker直接包含在官方鏡像源的Extras倉庫(CentOS-Base.repo下的[extras]節enable=1啓用)
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
(3)安裝docker
安裝 docker-io
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
歡迎關注本人的微信公衆號「大數據與人工智能Lab」(BigdataAILab),獲取更多資訊