Docker:CentOS7安装Docker
- 1. 官方安装文档
- 2. 卸载旧版
- 3. 配置Docker的yum库
- 4. 安装Docker
- 5. 启动和校验
- 6. 配置DOCKER镜像下载加速
1. 官方安装文档
https://docs.docker.com/engine/install/centos/
腾讯云搭建docker https://cloud.tencent.com/document/product/213/46000
2. 卸载旧版
首先如果系统中已经存在旧的Docker,则先卸载:
# 查看系统版本信息[root@hecs-230192~]# lsb_release-aLSBVersion::core-4.1-amd64:core-4.1-noarchDistributorID:CentOSDescription:CentOSLinuxrelease7.6.1810(Core)Release:7.6.1810Codename:Coreyum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine3. 配置Docker的yum库
首先要安装一个yum工具
yum install-y yum-utils安装成功后,执行命令,配置Docker的yum源:
sudo yum-config-manager \--add-repo\ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo[root@hecs-230192~]# sudo yum install-y yum-utilsLoadedplugins:fastestmirrorDeterminingfastest mirrors base|3.6kB00:00:00epel|4.3kB00:00:00extras|2.9kB00:00:00updates|2.9kB00:00:00(1/3):epel/x86_64/updateinfo|1.0MB00:00:00(2/3):epel/x86_64/primary_db|8.7MB00:00:00(3/3):updates/7/x86_64/primary_db|27MB00:00:00ResolvingDependencies-->Runningtransaction check--->Packageyum-utils.noarch0:1.1.31-54.el7_8 will be installed-->ProcessingDependency:python-kitchenforpackage:yum-utils-1.1.31-54.el7_8.noarch-->Runningtransaction check--->Packagepython-kitchen.noarch0:1.1.1-5.el7 will be installed-->ProcessingDependency:python-chardetforpackage:python-kitchen-1.1.1-5.el7.noarch-->Runningtransaction check--->Packagepython-chardet.noarch0:2.2.1-3.el7 will be installed-->FinishedDependencyResolutionDependenciesResolved==========================================================================================================================================PackageArchVersionRepositorySize==========================================================================================================================================Installing:yum-utils noarch1.1.31-54.el7_8 base122kInstallingfordependencies:python-chardet noarch2.2.1-3.el7 base227k python-kitchen noarch1.1.1-5.el7 base267kTransactionSummary==========================================================================================================================================Install1Package(+2Dependentpackages)Totaldownload size:616kInstalledsize:2.8MDownloadingpackages:(1/3):python-kitchen-1.1.1-5.el7.noarch.rpm|267kB00:00:00(2/3):python-chardet-2.2.1-3.el7.noarch.rpm|227kB00:00:00(3/3):yum-utils-1.1.31-54.el7_8.noarch.rpm|122kB00:00:00------------------------------------------------------------------------------------------------------------------------------------------Total1.9MB/s|616kB00:00:00Runningtransaction checkRunningtransaction testTransactiontest succeededRunningtransactionInstalling:python-chardet-2.2.1-3.el7.noarch1/3Installing:python-kitchen-1.1.1-5.el7.noarch2/3Installing:yum-utils-1.1.31-54.el7_8.noarch3/3Verifying:python-kitchen-1.1.1-5.el7.noarch1/3Verifying:yum-utils-1.1.31-54.el7_8.noarch2/3Verifying:python-chardet-2.2.1-3.el7.noarch3/3Installed:yum-utils.noarch0:1.1.31-54.el7_8DependencyInstalled:python-chardet.noarch0:2.2.1-3.el7 python-kitchen.noarch0:1.1.1-5.el7Complete![root@hecs-230192~]# sudo yum-config-manager \>--add-repo \>http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoLoadedplugins:fastestmirror adding repo from:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoto/etc/yum.repos.d/docker-ce.repo repo savedto/etc/yum.repos.d/docker-ce.repo4. 安装Docker
最后,执行命令,安装Docker
yum install-y docker-ce docker-ce-clicontainerd.io docker-buildx-plugin docker-compose-plugin5. 启动和校验
# 启动Docker[root@hecs-230192 ~]# systemctl start docker# 停止Dockersystemctl stop docker# 重启systemctl restart docker# 设置开机自启systemctl enable docker[root@hecs-230192 ~]# systemctl enable dockerCreated symlinkfrom/etc/systemd/system/multi-user.target.wants/docker.service to/usr/lib/systemd/system/docker.service.# 执行docker ps命令(查看正在运行得docker),如果不报错,说明安装启动成功dockerps[root@hecs-230192 ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6. 配置DOCKER镜像下载加速
vim/etc/docker/daemon.json 在其中加⼊加速镜像源地址即可(这⾥使⽤的是 ⽹易 的加速源,其他像 阿⾥云 、 DaoCloud 这些也都提供加速源,按需选择即可):{"registry-mirrors":["http://hub-mirror.c.163.com"]}加完加速地址后,重新加载配置⽂件,重启 docker 服务即可: systemctl daemon-reload systemctl restart docker.service也可以用腾讯云的
# 配置加速 sudo mkdir-p/etc/docker sudo tee/etc/docker/daemon.json<<-'EOF'{"registry-mirrors":["https://mirror.ccs.tencentyun.com"]}EOFsudo systemctl daemon-reload sudo systemctl restart docker