CentOS 安裝和刪除Docker

官方文檔: https://docs.docker.com/install/linux/docker-ce/centos/

CentOS 7 上安裝 docker

#extras 源中包名為docker

[root@centos7 ~]#yum list docker

Loaded plugins: fastestmirror

Repository base is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Loading mirror speeds from cached hostfile

* base: mirrors.tuna.tsinghua.edu.cn

* extras: mirrors.tuna.tsinghua.edu.cn

* updates: mirrors.tuna.tsinghua.edu.cn

Available Packages

docker.x86_64 ???2:1.13.1-103.git7f2769b.el7.centos ????????????

extras

下載rpm包安裝:

官方rpm包下載地址:

https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

阿里鏡像下載地址:

https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/

通過(guò)yum源安裝:

由于官網(wǎng)的yum源太慢,下面使用阿里云的Yum源進(jìn)行安裝

rm -rf /etc/yum.repos.d/*

#CentOS 7 安裝docker依賴三個(gè)yum源:Base,Extras,docker-ce

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-

ce/linux/centos/docker-ce.repo

yum clean all

yum -y install docker-ce

systemctl enable --now docker


刪除 docker

[root@centos7 ~]#yum remove docker-ce

#刪除docker資源存放的相關(guān)文件

[root@centos7 ~]#rm -rf /var/lib/docker

范例: CentOS 7 基于阿里云的安裝docker方法

阿里云說(shuō)明:?

https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11sUMKNV

# step 1: 安裝必要的一些系統(tǒng)工具

yum install -y yum-utils device-mapper-persistent-data lvm2

# Step 2: 添加軟件源信息

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-

ce/linux/centos/docker-ce.repo

# Step 3: 更新并安裝Docker-CE

yum makecache fast

yum -y install docker-ce

# Step 4: 開(kāi)啟Docker服務(wù)

service docker start

# 注意:

# 官方軟件源默認(rèn)啟用了最新的軟件,您可以通過(guò)編輯軟件源的方式獲取各個(gè)版本的軟件包。例如官方并沒(méi)有

將測(cè)試版本的軟件源置為可用,您可以通過(guò)以下方式開(kāi)啟。同理可以開(kāi)啟各種測(cè)試版本等。

# vim /etc/yum.repos.d/docker-ee.repo

# ?將[docker-ce-test]下方的enabled=0修改為enabled=1

#

# 安裝指定版本的Docker-CE:

# Step 1: 查找Docker-CE的版本:

# yum list docker-ce.x86_64 --showduplicates | sort -r

# ?Loading mirror speeds from cached hostfile

# ?Loaded plugins: branch, fastestmirror, langpacks

# ?docker-ce.x86_64 ?????17.03.1.ce-1.el7.centos ?????docker-ce-

stable

范例: 在CentOS 7上安裝指定版本的docker

# ?docker-ce.x86_64 ?????17.03.1.ce-1.el7.centos ?????@docker-ce-

stable

# ?docker-ce.x86_64 ?????17.03.0.ce-1.el7.centos ?????docker-ce-

stable

# ?Available Packages

# Step2: 安裝指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)

yum -y install docker-ce-[VERSION]

#示例

[root@centos7 ~]#yum -y install docker-ce-19.03.12-3.el7

范例: 在CentOS 7上安裝指定版本的docker

[root@centos7 ~]#cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

[root@centos7 ~]# ls /etc/yum.repos.d/

backup base.repo

[root@centos7 ~]# wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Saving to: ‘/etc/yum.repos.d/docker-ce.repo’

100%[====================================================================>]

2,640 ???--.-K/s ?in 0s ??

2020-01-23 21:56:21 (505 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved

[2640/2640]

[root@centos7 ~]# ls /etc/yum.repos.d/

backup base.repo docker-ce.repo

[root@centos7 ~]# yum clean all

Loaded plugins: fastestmirror

Cleaning repos: base docker-ce-stable epel extras

Cleaning up list of fastest mirrors

[root@centos7 ~]# yum repolist

repo id ?????????repo name ????????????????????

status

base ???????????CentOS ??????????????????????

10,019

docker-ce-stable/x86_64 ?Docker CE Stable - x86_64 ?????????????

??63

epel/7/x86_64 ??????EPEL ???????????????????????

13,513

extras/7/x86_64 ?????extras ??????????????????????

??307

repolist: 23,902

[root@centos7 ~]# yum list docker-ce* --showduplicates | sort -r

Loading mirror speeds from cached hostfile

Loaded plugins: fastestmirror

docker-ce.x86_64 ????????3:19.03.5-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:19.03.4-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:19.03.3-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:19.03.2-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:19.03.1-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:19.03.0-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.9-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.8-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.7-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.6-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.5-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.4-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.3-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.2-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.1-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????3:18.09.0-3.el7 ????????docker-ce-stable

docker-ce.x86_64 ????????18.06.3.ce-3.el7 ???????docker-ce-stable

docker-ce.x86_64 ????????18.06.2.ce-3.el7 ???????docker-ce-stable

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

docker-ce.x86_64 ????????17.09.1.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.09.0.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.06.2.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.06.1.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.06.0.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.03.3.ce-1.el7 ???????docker-ce-stable

docker-ce.x86_64 ????????17.03.2.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.03.1.ce-1.el7.centos ????docker-ce-stable

docker-ce.x86_64 ????????17.03.0.ce-1.el7.centos ????docker-ce-stable

docker-ce-selinux.noarch ????17.03.3.ce-1.el7 ???????docker-ce-stable

docker-ce-selinux.noarch ????17.03.2.ce-1.el7.centos ????docker-ce-stable

docker-ce-selinux.noarch ????17.03.1.ce-1.el7.centos ????docker-ce-stable

docker-ce-selinux.noarch ????17.03.0.ce-1.el7.centos ????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.5-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.4-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.3-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.2-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.1-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:19.03.0-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.9-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.8-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.7-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.6-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.5-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.4-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.3-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.2-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.1-3.el7 ????????docker-ce-stable

docker-ce-cli.x86_64 ??????1:18.09.0-3.el7 ????????docker-ce-stable

Available Packages

[root@centos7 ~]# yum -y install docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7

Dependencies Resolved

================================================================================

=========

Package ????????????Arch ??????Version ????????

Repository ????????Size

================================================================================

Installing:

docker-ce ???????????x86_64 ?????3:18.09.9-3.el7 ????

docker-ce-stable ??????21 M

docker-ce-cli ?????????x86_64 ?????1:18.09.9-3.el7 ????

docker-ce-stable ??????16 M

Installing for dependencies:

audit-libs-python ???????x86_64 ?????2.8.4-4.el7 ??????

base ????????????76 k

checkpolicy ??????????x86_64 ?????2.5-8.el7 ???????

base ???????????295 k

container-selinux ???????noarch ?????2:2.107-3.el7 ?????

extras ???????????39 k

containerd.io ?????????x86_64 ?????1.2.10-3.2.el7 ????

docker-ce-stable ??????23 M

libcgroup ???????????x86_64 ?????0.41-20.el7 ??????

base ????????????66 k

libsemanage-python ???????x86_64 ?????2.5-14.el7 ??????

base ???????????113 k

policycoreutils-python ?????x86_64 ?????2.5-29.el7 ??????

base ???????????456 k

python-IPy ???????????noarch ?????0.75-6.el7 ??????

base ????????????32 k

setools-libs ??????????x86_64 ?????3.3.8-4.el7 ??????

base ???????????620 k

Transaction Summary

======================================================================

==============================

Install ?2 Packages (+9 Dependent packages)

Total download size: 62 M

Installed size: 258 M

Downloading packages:

(1/4): container-selinux-2.107-3.el7.noarch.rpm ???????????????

???| ?39 kB ?00:00:00 ?

warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/containerd.io-1.2.10-

3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY

Public key for containerd.io-1.2.10-3.2.el7.x86_64.rpm is not installed

(2/4): containerd.io-1.2.10-3.2.el7.x86_64.rpm ????????????????

???| ?23 MB ?00:00:03 ?

(3/4): docker-ce-18.09.9-3.el7.x86_64.rpm ??????????????????

???| ?21 MB ?00:00:04 ?

(4/4): docker-ce-cli-18.09.9-3.el7.x86_64.rpm ????????????????

???| ?16 MB ?00:00:01 ???????

Complete!

[root@centos7 ~]# docker version

Client:

Version: ?????18.09.9

API version: ???1.39

Go version: ???go1.11.13

Git commit: ???039a7df9ba

Built: ??????Wed Sep ?4 16:51:21 2019

OS/Arch: ?????linux/amd64

Experimental: ???false

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the

docker daemon running?

[root@centos7 ~]# systemctl enable --now docker

[root@centos7 ~]# docker version

Client:

Version: ?????18.09.9

Go version: ???go1.11.13

Git commit: ???039a7df

Built: ?????Wed Sep ?4 16:22:32 2019

OS/Arch: ????linux/amd64

Experimental: ??false

[root@centos7 ~]#


范例: 在CentOS8安裝docker

[root@centos8 ~]#tee /etc/yum.repos.d/docker.repo <<EOF

[docker]

name=docker

gpgcheck=0

baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/

EOF

[root@centos8 ~]#dnf -y install docker-ce


最后編輯于
?著作權(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)容