Centos 8安裝docker

CentOS 8.2 安裝docker

轉(zhuǎn)載于http://www.itdecent.cn/p/b038f63fe929

參考 https://juejin.im/post/5e3032575188252c6e182a55

軟件更新

把相關(guān)軟件都更新

 yum update

卸載舊版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

安裝yum-utils軟件包(提供yum-config-manager 實(shí)用程序)并設(shè)置穩(wěn)定的存儲(chǔ)庫(kù)。

yum install -y yum-utils

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

阿里云yum源

yum-config-manager --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

查看Docker版本
yum list docker-ce --showduplicates | sort -r

安裝Docker

報(bào)錯(cuò)

[root@localhost ~]# yum install docker-ce
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
上次元數(shù)據(jù)過(guò)期檢查:0:00:38 前,執(zhí)行于 2020年01月28日 星期二 17時(shí)02分33秒。
錯(cuò)誤:
 問(wèn)題: package docker-ce-3:19.03.5-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(嘗試添加 '--skip-broken' 來(lái)跳過(guò)無(wú)法安裝的軟件包 或 '--nobest' 來(lái)不只使用最佳選擇的軟件包)

這個(gè)時(shí)候需要安裝containerd.io,我們可以到這個(gè)網(wǎng)站https://download.docker.com/linux/centos/7/x86_64/stable/Packages/,找到最新的去安裝

[root@localhost ~]# dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

如果連接超時(shí)錯(cuò)誤
解決方法:換成國(guó)內(nèi)的源

[root@localhost yum.repos.d]#  dnf install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

繼續(xù)進(jìn)行安裝

[root@localhost ~]# yum install docker-ce docker-ce-cli

啟動(dòng)Docker,并設(shè)置為開(kāi)機(jī)自啟
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

啟動(dòng)docker服務(wù)遠(yuǎn)程允許訪(fǎng)問(wèn)

1、編輯服務(wù)器上的docker.service文件

vi /usr/lib/systemd/system/docker.service

大約 在 14行 原來(lái)的值

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

修改為

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

2、保存修改退出,重啟docker

systemctl daemon-reload

service docker restart

3、測(cè)試遠(yuǎn)程連接是否正常 輸出下面的內(nèi)容 如果出現(xiàn)以下內(nèi)容則能正常連接:

curl http://localhost:2375/version

{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"19.03.9","Details":{"ApiVersion":"1.40","Arch":"amd64","BuildTime":"2020-05-15T00:24:05.000000000+00:00","Experimental":"false","GitCommit":"9d988398e7","GoVersion":"go1.13.10","KernelVersion":"4.18.0-147.el8.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.2.6","Details":{"GitCommit":"894b81a4b802e4eb2a91d1ce216b8817763c29fb"}},{"Name":"runc","Version":"1.0.0-rc8","Details":{"GitCommit":"425e105d5a03fabd737a126ad93d62a9eeede87f"}},{"Name":"docker-init","Version":"0.18.0","Details":{"GitCommit":"fec3683"}}],"Version":"19.03.9","ApiVersion":"1.40","MinAPIVersion":"1.12","GitCommit":"9d988398e7","GoVersion":"go1.13.10","Os":"linux","Arch":"amd64","KernelVersion":"4.18.0-147.el8.x86_64","BuildTime":"2020-05-15T00:24:05.000000000+00:00"}

4、開(kāi)放端口

需要將2375端口進(jìn)行開(kāi)放才能被遠(yuǎn)程連接,如果是阿里云主機(jī)的話(huà),可以直接登錄阿里云去進(jìn)行開(kāi)放

如果是虛擬機(jī)的話(huà),可以用以下命令進(jìn)行開(kāi)放:

firewall-cmd --zone=public --add-port=2375/tcp --permanent

如果是虛擬機(jī) 也可以暫時(shí) 關(guān)閉 防火墻

查看防火墻運(yùn)行狀態(tài)

firewall-cmd --state
running

running 表示正在 運(yùn)行

關(guān)閉防火墻命令

systemctl stop firewalld

本機(jī) 瀏覽器上輸入 http://192.168.1.98:2375/version

有返回結(jié)果,則可以正常使用了

在idea中 正常連接了

防火墻開(kāi)啟 有可能阻止容器間訪(fǎng)問(wèn) 使用下面的設(shè)置修改 使防火墻運(yùn)行狀態(tài)下可以使容器間正常通訊
#配置docker0服務(wù)到受信任連接
[root@localhost ~]# nmcli connection modify docker0 connection.zone trusted
#停止NetworkManager(檢測(cè)網(wǎng)絡(luò)、自動(dòng)連接網(wǎng)絡(luò)的程序)服務(wù)
[root@localhost ~]# systemctl stop NetworkManager.service
#修改docker網(wǎng)絡(luò)接口為內(nèi)部區(qū)域(永久)
[root@localhost ~]# firewall-cmd --permanent --zone=trusted --change-interface=docker0
success
#啟動(dòng)NetworkManager(檢測(cè)網(wǎng)絡(luò)、自動(dòng)連接網(wǎng)絡(luò)的程序)服務(wù)
[root@localhost ~]# systemctl start NetworkManager.service
#配置docker0服務(wù)到受信任連接
[root@localhost ~]# nmcli connection modify docker0 connection.zone trusted
#重啟docker服務(wù)
[root@localhost ~]# systemctl restart docker.service

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容