1. 程式人生 > >002.Docker安裝部署

002.Docker安裝部署

一 docker安裝-CentOS系統

1.1 docker自動安裝指令碼

  1 [email protected]:~# wget -qO- https://get.docker.com/ | sh
  2 或——
  3 [email protected]:~# curl -sSL https://get.docker.com/ | sh
  注意:若出現以下錯誤,可使用yum解決依賴—— Delta RPMs disabled because /usr/bin/yum provides applydeltarpmnot installed.
  1 yum provides applydeltarpm			#查詢缺少的applydeltarpm所在包
  2
yum install libdevmapper* -y 3 yum -y install deltarpm #安裝此包 4 yum install -y epel-release #有可能會依舊提示錯誤,安裝此包即可 5 [email protected]:~# docker version #查詢docker版本
 

1.2 docker yum安裝

  1 [email protected]:~# yum -y remove docker \
  2                   docker-client \
  3
docker-client-latest \ 4 docker-common \ 5 docker-latest \ 6 docker-latest-logrotate \ 7 docker-logrotate \ 8 docker-selinux \ 9 docker-engine-selinux \ 10 docker-engine #若存在舊版需要全新安裝可解除安裝舊版 11
[email protected]:~# yum -y update 12 [email protected]:~# yum install -y yum-utils \ 13 device-mapper-persistent-data \ 14 lvm2 15 [email protected]:~# yum-config-manager \ 16 --add-repo \ 17 https://download.docker.com/linux/centos/docker-ce.repo #配置docker源
  提示:也可使用國內阿里雲——
  1 [email protected]:~# yum-config-manager \
  2 --add-repo \
  3 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4 [email protected]:~# yum-config-manager --enable docker-ce-edge	        #開啟源
  5 [email protected]:~# yum-config-manager --enable docker-ce-test	        #開啟源
  6 [email protected]:~# yum -y install docker-ce				#安裝docker
  7 [email protected]:~# yum -y install docker-registry			#安裝docker倉庫
  8 [email protected]:~# systemctl start docker.service
  9 [email protected]:~# systemctl enable docker.service		        #設為開機啟動
   

二 docker安裝-Ubuntu系統

2.1 更新源資料庫

  1 [email protected]:~# apt-get remove docker docker-engine docker.io	#解除安裝舊版
  2 [email protected]:~# sudo apt-get update
 

2.2 安裝軟體包

  1 [email protected]:~# sudo apt-get -y install \
  2 apt-transport-https \
  3 ca-certificates \
  4 curl \
  5 software-properties-common			#安裝軟體包以允許apt通過HTTPS使用儲存庫
 

2.3 新增Docker的官方GPG金鑰

  1 [email protected]:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
05_thumb1 注意:也可新增阿里雲GPG: curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

2.4 驗證祕鑰指紋

  1 [email protected]:~# sudo apt-key fingerprint 0EBFCD88
06_thumb1

2.5 配置倉庫並在此更新源

  1 [email protected]:~# sudo add-apt-repository \
  2 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  3 $(lsb_release -cs) \
  4 stable"
  5 [email protected]:~# sudo apt-get update
  注意:國內建議配置為阿里倉庫,命令如下:
  1 [email protected]:~# sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  2 [email protected]:~# sudo apt-get update
 

2.6 安裝docker ce

  1 [email protected]:~# sudo apt-get -y install docker-ce

2.7 測試並檢視版本

  1 [email protected]:~# sudo docker run hello-world
  2 [email protected]:~# sudo docker version
  07_thumb1 注意:若存在舊版本可執行以下命令解除安裝舊版本—— apt-get remove docker docker-engine docker-common container-selinux docker-selinux

三 docker相關優化

3.1 配置docker加速器

  1 [email protected]:~# mkdir -p /etc/docker
  2 [email protected]cker:~# vim /etc/docker/daemon.json
  3 {
  4    "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"]
  5 }
  6 [email protected]:~# cat /etc/docker/daemon.json
  7 {
  8   "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"]
  9 }
 10 [email protected]:~# systemctl daemon-reload
 11 [email protected]:~# systemctl restart docker
 12 [email protected]:~# sudo systemctl enable docker
  提示:docker通過https://hub.docker.com/搭建映象共享生態系統,由於從國外拉取源比較慢,建議配置國內阿里加速器。

3.2 更改docker映象路徑

  1 [email protected]:~# vi /usr/lib/systemd/system/docker.service
  2 ExecStart=/usr/bin/dockerd-current --graph=/data/docker		#僅需要追加新路徑
  3 [email protected]:~# systemctl daemon-reload
  4 [email protected]:~# systemctl restart docker
參考: https://docs.docker.com/install/