Linux CentOS 安裝 docker 和 docker-compose

panweiheng發表於2020-07-10

一、linux centos安裝docker
我是虛擬機器裝的Centos7,linux 3.10 核心,docker官方說至少3.8以上,建議3.10以上(ubuntu下要linux核心3.8以上, RHEL/Centos 的核心修補過, centos6.5的版本就可以——這個可以試試)
1,root賬戶登入,檢視核心版本如下
[root@localhost ~]# uname -a
Linux localhost.qgc 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2,(可選)把yum包更新到最新(生產環境慎重!yum update會對軟體包和核心升級,此處只是為了排除系統環境的影響,來自筆者的備註—2019年10月30日)
3,安裝需要的軟體包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.aliyun.com * updates: centos.ustc.edu.cn
….
4,設定yum源
[root@localhost ~]# yum-config-manager –add-repo download.docker.com/linux/centos/d...
已載入外掛:fastestmirror, langpacks
adding repo from: download.docker.com/linux/centos/d...
grabbing file download.docker.com/linux/centos/d... to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

5,可以檢視所有倉庫中所有docker版本,並選擇特定版本安裝

[root@localhost ~]# yum list docker-ce –showduplicates | sort -r
已載入外掛:fastestmirror, langpacks
可安裝的軟體包 * updates: centos.ustc.edu.cn
Loading mirror speeds from cached hostfile * extras: mirrors.aliyun.com
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable

安裝之前解除安裝舊版本(如果安裝過舊版本的話)
yum remove docker docker-common docker-selinux docker-engine

6,安裝Docker,命令:yum install docker-ce-版本號,我選的是17.12.1.ce,如下

[root@localhost ~]# yum install docker-ce-17.12.1.ce
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.aliyun.com * updates: centos.ustc.edu.cn
base | 3.6 kB 00:00 docker-ce-stable | 2.9 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 正在解決依賴關係 –> 正在檢查事務 —> 軟體包 docker-ce.x86_64.0.17.12.1.ce-1.el7.centos 將被 安裝 –> 正在處理依賴關係 container-selinux >= 2.9,它被軟體包 docker-ce-17.12.1.ce-1.el7.centos.x86_64 需要

7, 啟動Docker,命令:systemctl start docker,然後加入開機啟動,如下

[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

8,docker version 驗證安裝是否成功(有client和service兩部分表示docker安裝啟動都成功了)

9,配置阿里映象加速器

去阿里雲註冊個賬號,獲取映象加速地址
建立或修改 /etc/docker/daemon.json 檔案,修改為如下形式

{
“registry-mirrors”: [“http://hub-mirror.c.163.com"]
}
systemctl restart docker.service

二、安裝docker-compose
1,安裝docker-compose相對比較簡單,可以直接去(github.com/docker/compose/releases) 下載然後選擇相應的版本,或者直接執行如下命令安裝,安裝完後docker-compose會被安裝到/usr/local/bin目錄下
curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s-uname -m` -o /usr/local/bin/docker-compose

2,設定docker-compose可執行

sudo chmod +x /usr/local/bin/docker-compose
3, 檢視docker-compose是否安裝成功
docker-compose –version

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章