CentOS6.X下Docker如何安裝

小編給大家分享一下CentOS6.X下Docker如何安裝,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)徐匯免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

[X] 一、禁用selinux

由于Selinux和LXC有沖突,所以需要禁用selinux.編輯/etc/selinux/config,設(shè)置兩個(gè)關(guān)鍵變量.

SELINUX=disabled
SELINUXTYPE=targeted
[X] 二、安裝Fedora EPEL源
rpm -ivh ./epel-release-6-8.noarch.rpm  
或者:  
#yum install http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
[X] 三、添加hop5.repo源
cp ./hop5.repo /etc/yum.repos.d        
或者:  
#cd /etc/yum.repos.d        
#wget http://www.hop5.in/yum/el6/hop5.repo
[X] 四、安裝Docker
yum安裝
[X] 升級(jí)帶aufs模塊的3.10內(nèi)核((可選)
yum install kernel-ml-aufs kernel-ml-aufs-devel
  1. 修改grub的主配置文件/etc/grub.conf,設(shè)置default=0,表示第一個(gè)title下的內(nèi)容為默認(rèn)啟動(dòng)的kernel(一般新安裝的內(nèi)核在第一個(gè)位置)。

  2. 重啟系統(tǒng)reboot now,

  3. 然后執(zhí)行uname -r,查看是否已經(jīng)是3.10內(nèi)核!

[root@localhost ~]# uname -r
3.10.5-3.el6.x86_64

  1. 執(zhí)行grep aufs /proc/filesystems,查看內(nèi)核是否支持aufs!

[root@localhost ~]# grep aufs /proc/filesystems
nodev aufs

[X] 安裝docker
yum install redhat-lsb

yum install iptables
chkconfig ip6tables off
chkconfig iptables off
service ip6tables stop
service iptables stop

yum install device-mapper-libs
yum install libcgroup*
yum install docker-io

如果報(bào)錯(cuò):Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

解決辦法是編輯/etc/yum.repos.d/epel.repo,把基礎(chǔ)的恢復(fù),鏡像的地址注釋掉

#baseurl
mirrorlist

改成

baseurl
#mirrorlist

然后執(zhí)行: yum clean all
=============================================================================================================================================================================================================================================
 Package                                                       Arch                                                  Version                                                       Repository                                           Size
=============================================================================================================================================================================================================================================
Installing:
 docker-io                                                     x86_64                                                1.2.0-3.el6                                                   epel                                                4.2 M
Installing for dependencies:
 lua-alt-getopt                                                noarch                                                0.7.0-1.el6                                                   epel                                                6.9 k
 lua-filesystem                                                x86_64                                                1.4.2-1.el6                                                   epel                                                 24 k
 lua-lxc                                                       x86_64                                                1.0.6-1.el6                                                   epel                                                 15 k
 lxc                                                           x86_64                                                1.0.6-1.el6                                                   epel                                                120 k
 lxc-libs                                                      x86_64                                                1.0.6-1.el6                                                   epel                                                248 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install       6 Package(s)

Downloading Packages:
(1/6): docker-io-1.2.0-3.el6.x86_64.rpm                                                                                                                                                                               | 4.2 MB     00:02
(2/6): lua-alt-getopt-0.7.0-1.el6.noarch.rpm                                                                                                                                                                          | 6.9 kB     00:00
(3/6): lua-filesystem-1.4.2-1.el6.x86_64.rpm                                                                                                                                                                          |  24 kB     00:00
(4/6): lua-lxc-1.0.6-1.el6.x86_64.rpm                                                                                                                                                                                 |  15 kB     00:00
(5/6): lxc-1.0.6-1.el6.x86_64.rpm                                                                                                                                                                                     | 120 kB     00:00
(6/6): lxc-libs-1.0.6-1.el6.x86_64.rpm                                                                                                                                                                                | 248 kB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rpm手工安裝:

先執(zhí)行

rpm --nodeps -ev $(rpm -qa | grep -i 'device-mapper-libs-')
rpm --nodeps -ev $(rpm -qa | grep -i 'device-mapper-')
rpm --nodeps -ev $(rpm -qa | grep -i 'device-mapper-event-libs-')
rpm --nodeps -ev $(rpm -qa | grep -i 'device-mapper-event-')

rpm -ivh ./device-mapper-event-1.02.90-2.el6.x86_64.rpm ./device-mapper-event-libs-1.02.90-2.el6.x86_64.rpm ./device-mapper-1.02.90-2.el6.x86_64.rpm ./device-mapper-libs-1.02.90-2.el6.x86_64.rpm

再執(zhí)行

rpm -ivh ./lxc-libs-1.0.6-1.el6.x86_64.rpm
rpm -ivh ./lua-alt-getopt-0.7.0-1.el6.noarch.rpm
rpm -ivh ./lua-filesystem-1.4.2-1.el6.x86_64.rpm
rpm -ivh ./lua-lxc-1.0.6-1.el6.x86_64.rpm
rpm -ivh ./lxc-1.0.6-1.el6.x86_64.rpm
#6.4版本以下需要 rpm -ivh ./libcgroup-0.40.rc1-5.el6.x86_64.rpm
rpm -ivh ./docker-io-1.3.2-2.el6.x86_64.rpm
[X] 五、初步驗(yàn)證docker

輸入docker -h,如果有如下輸出,就證明docker在形式上已經(jīng)安裝成功.

# docker -h 
Usage of docker: 
  -D=false: Enable debug mode 
  -H=[]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise 
  -api-enable-cors=false: Enable CORS headers in the remote API 
  -b="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking
  -bip="": Use this CIDR notation address for the network bridge's IP, not compatible with -b 
  -d=false: Enable daemon mode 
  -DNS=[]: Force docker to use specific DNS servers 
  -g="/var/lib/docker": Path to use as the root of the docker runtime 
  -icc=true: Enable inter-container communication 
  -ip="0.0.0.0": Default IP address to use when binding container ports 
  -iptables=true: Disable docker's addition of iptables rules 
  -p="/var/run/docker.pid": Path to use for daemon PID file
  -r=true: Restart previously running containers 
  -s="": Force the docker runtime to use a specific storage driver 
  -v=false: Print version information and quit
[X] 六 、啟動(dòng)docker服務(wù):
service docker start
#docker -d -H unix:///var/run/docker.sock
[X] 七 、查找映象:

docker search 映象名字 從index.docker.io搜尋所需鏡像. 去https://index.docker.io獲取鏡像相關(guān)的信息.

[X] 八 、進(jìn)入 Docker 容器:

創(chuàng)建vi /bin/docker-enter.sh

#!/bin/sh

if [ -e $(dirname "$0")/nsenter ]; then
  # with boot2docker, nsenter is not in the PATH but it is in the same folder
  NSENTER=$(dirname "$0")/nsenter
else
  NSENTER=nsenter
fi

if [ -z "$1" ]; then
  echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"
  echo ""
  echo "Enters the Docker CONTAINER and executes the specified COMMAND."
  echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."
else
  PID=$(docker inspect --format "{{.State.Pid}}" "$1")
  if [ -z "$PID" ]; then
    exit 1
  fi
  shift

  OPTS="--target $PID --mount --uts --ipc --net --pid --"

  if [ -z "$1" ]; then
    # No command given.
    # Use su to clear all host environment variables except for TERM,
    # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH,
    # and start a login shell.
    "$NSENTER" $OPTS su - root
  else
    # Use env to clear all host environment variables.
    "$NSENTER" $OPTS env --ignore-environment -- "$@"
  fi
fi

加上可執(zhí)行chmod +x /bin/docker-enter.sh 運(yùn)行docker-enter.sh <container id>,這樣就進(jìn)入到指定的容器中!

[X] 附錄:低版本的Redhat(6.3)可能要手動(dòng)掛載cgroup

我們首選禁用cgroup對(duì)應(yīng)服務(wù)cgconfig.

  service cgconfig stop # 關(guān)閉服務(wù) 
  chkconfig cgconfig off # 取消開(kāi)機(jī)啟動(dòng)

然后掛載cgroup,可以命令行掛載

  mount -t cgroup none /cgroup  #僅本次有效

或者修改配置文件,編輯/etc/fstab,加入

none                    /cgroup                 cgroup  defaults        0 0

以上是“CentOS6.X下Docker如何安裝”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站標(biāo)題:CentOS6.X下Docker如何安裝
文章轉(zhuǎn)載:http://muchs.cn/article36/iejdsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)網(wǎng)站導(dǎo)航、電子商務(wù)、響應(yīng)式網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作