1. 程式人生 > >centos6.9環境下docker安裝

centos6.9環境下docker安裝

轉載:https://www.linuxidc.com/Linux/2018-02/150834.htm

由於Docker要求執行的linux核心版本為3.8以上,因此,在安裝之前,要檢視一下宿主機作業系統的核心版本,否則如果是核心低於3.8,能夠成功安裝Docker,但進入Docker後,會自動退出。

1、下載安裝CentOS 6.9

CentOS 6 系列,最新版本為6.9,由於 Docker 只能執行在64位系統上,因此到CentOS的官網上選擇某個映象 下載  CentOS 6.9 64位

2、升級CentOS的Linux核心

CentOS 6.9預設的linux核心版本為2.6,CentOS 7預設的linux核心版本為3.10,因此,對於CentOS 6.9則需進行核心版本的升級

1)進入更新linux核心的網址  http://elrepo.org/tiki/tiki-index.php

2)按照操作指引進行核心更新,在root賬號下執行以下指令

(1)匯入 public key

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

(2)安裝ELRepo

針對Centos6,

針對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

3、安裝 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 已經完全安裝成功了

4、解除安裝docker

如果要解除安裝docker,也非常簡單,檢視docker安裝包

yum list installed | grep docker

然後刪除安裝包

yum -y remove docker-io.x86_64

刪除映象或容器

rm -rf /var/lib/docker

更多Docker相關教程見以下內容: 

Docker 的詳細介紹請點這裡
Docker 的下載地址請點這裡