1. 程式人生 > >centos6安裝最新docker

centos6安裝最新docker

 

 

 

 

1.升級系統核心

檢視核心版本: 

uname -r
2.6.32-573.8.1.el6.x86_64

匯入elrepo的key:

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

curl 報ssl錯誤,解決辦法:

yum update -y nss curl libcurl openssh

安裝elrepo.repo: 

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

安裝核心:

(安裝最新版核心)yum --enablerepo=elrepo-kernel -y install kernel-ml

(安裝長期穩定版核心)yum --enablerepo=elrepo-kernel -y install kernel-lt

修改grub.conf檔案:

vim /etc/grub.conf --> default=0

重啟伺服器檢視核心:

reboot
uname -r
4.4.162-1.el6.elrepo.x86_64

2.安裝docker

對於centos6好像是沒有yum最新版,只能通過升級方式了。

方法一:centos6下安裝epel源,我的伺服器好像不行。

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm sudo rpm -Uvh epel-release-6*.rpm

yum install docker-io

方法二:生成docker.repo

tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF


yum update
yum install docker-engine


 

測試docker:

docker --version

service docker status

3.升級docker

原始碼編譯docker(需要伺服器有老版本的docker):
升級git:
1.安裝環境 

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc -y
yum install gcc perl-ExtUtils-MakeMaker -y

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz 
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install

yum install xmlto -y


2.安裝配置

yum remove git

wget https://github.com/git/git/archive/v2.2.1.tar.gz

tar zxvf v2.2.1.tar.gz

cd git-2.2.1

make configure

./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv

make all doc

make install install-doc install-html

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc

source /etc/bashrc


安裝golang
#Docker使用Golang開發

wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
tar xzf go1.10.linux-amd64.tar.gz -C /usr/local
mkdir /usr/local/gopackage

加入環境變數
vi /etc/profile 
GOROOT=/usr/local/go
GOPATH=/usr/local/gopackage
PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOROOT GOPATH PATH

source /etc/profile

下載原始碼並編譯:

#docker改名為moby,不用糾結

git clone https://github.com/moby/moby
cd moby


#要啥版本你自己看著切換,我們選擇比較穩定的最新版本17.03.2

git checkout v17.03.2-ce
make build

#編譯原始碼:

下載1.9.1然後替換
curl -sSL -O https://get.docker.com/builds/Linux/x86_64/docker-1.9.1
chmod +x docker-1.9.1
sudo mv docker-1.9.1 /usr/bin/docker
service docker restart
編譯原始碼
make binary
make instal

解除安裝並更新:

#解除安裝舊的docker
yum remove docker-io -y
#清理下遺留的檔案
rm -rf /var/lib/docker/*
#docker 配置檔案
wget https://raw.githubusercontent.com/moby/moby/master/contrib/init/sysvinit-redhat/docker.sysconfig -O /etc/sysconfig/docker
#docker init啟動檔案
wget https://raw.githubusercontent.com/moby/moby/master/contrib/init/sysvinit-redhat/docker -O /etc/init.d/docker
#修改啟動檔案中dockerd的位置
sed -i "27s#usr/bin#usr/local/bin#g" /etc/init.d/docker
#修改環境變數,覆蓋functions指令碼中的PATH,防止無法找到docker-container等程式
sed -i "23s#functions#functions\nexport PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin#g" /etc/init.d/docker
#啟動
service docker restart
#檢視版本
docker version