系列目錄html
Docker從1.13版本以後採用時間線的方式做爲版本號,分爲社區版CE和企業版EE。linux
社區版是免費提供給我的開發者和小型團體使用的,企業版會提供額外的收費服務,好比通過官方測試認證過的基礎設施、容器、插件等。docker
社區版按照stable和edge兩種方式發佈,每一個季度更新stable版本,如17.06,17.09;每月份更新edge版本,如17.09,17.10。json
1) Docker 要求 CentOS 系統的內核版本高於 3.10 ,查看本頁面的前提條件來驗證你的CentOS 版本是否支持 Docker 。centos
經過 uname -r 命令查看你當前的內核版本socket
uname -r
須要注意的是如下命令均是在
root
帳戶下執行的,若是是普通帳戶有些命令則可能須要加上sudo
測試
2)執行 yum updateui
yum update非必選項,可是建議執行操做this
3)卸載舊版本docker阿里雲
yum -y remove docker docker-common docker-selinux docker-engine
3)設置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里雲yum源
須要注意的是,目前(2019年3月)測試的時候,docker不設置阿里雲鏡像源也是能正常安裝的,而且阿里雲鏡像源地址也可能會更改,因此以上地址可能會返回404,若是以上鏡像源地址不存在也能夠忽略這一步直接進行下一步.
4)查看全部倉庫中全部docker版本,並選擇特定版本安裝
yum list docker-ce --showduplicates | sort -r
5)安裝docker
yum install -y docker-ce #因爲repo中默認只開啓stable倉庫,故這裏安裝的是最新穩定版17.12.0 yum install -y <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce
6)啓動docker並加入開機自動啓動
systemctl start docker systemctl enable docker
7)配置阿里雲鏡像加速
mkdir -p /etc/docker vi /etc/docker/daemon.json
添加如下內容
{"registry-mirrors": ["https://5f2jam6c.mirror.aliyuncs.com", "http://hub-mirror.c.163.com"] }
8)從新加載配置文件
systemctl reload docker
9)重啓docker
systemctl restart docker
安裝過程當中可能會出現的問題:
1.正在處理依賴關係 docker-ce-selinux >= 17.03.0.ce-1.el7.centos,它被軟件包 docker-ce-17.03.0.ce-1.el7.centos.x86_64 須要
軟件包 docker-ce-selinux 已經被 docker-ce-cli 取代,可是取代的軟件包並未知足需求」
等一大串的問題
這時咱們須要經過 yum install 安裝一個rpm包
經過這個地址咱們查看和咱們安裝docker版本一直的rpm包
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
經過
yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
問題解決
2.非root用戶使用docker命令報錯
以上咱們爲了方便在安裝過程當中使用的是root帳戶,然而實際操做中咱們可能更多的是用普通用戶操做docker命令.從root用戶切到普通用戶執行docker命令時會報以下錯誤
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
官方解釋以下:
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user. To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
sudo groupadd docker
此步驟並不是必須,默認狀況下docker安裝過程當中會自動建立一個docker用戶組
sudo gpasswd -a ${USER} docker
注意以上命令只能用當前用戶來操做,由於變量
USER
獲取的是當前用戶,若是要以root用戶來操做,則須要指定的是具體的用戶名,而非此變量
這裏並非批退出系統,只要切換一下用戶便可,好比先切到root用戶而後再切回來就能夠了
3.安裝docker時報container-selinux >= 2.9
錯誤
因爲測試環境的機器是不一樣批准到來的,第一批安裝很是順序,第二批是直接放置在辦公室的PC機,也很是不順序,安裝過程遇到各類各樣麻煩.
上面說過,加入集羣時發現docker沒有安裝成功,安裝docker時出現瞭如下錯誤
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-edge)
Requires: container-selinux >= 2.9
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
這個報錯是container-selinux版本低或者是沒安裝的緣由
yum 安裝container-selinux 通常的yum源又找不到這個包
須要安裝epel源 才能yum安裝container-selinux
而後在安裝docker-ce就能夠了。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release #阿里雲上的epel源
yum makecache
而後yum install container-selinux