JayGao

JayGao的个人博客,分享技术,记录生活,感谢您的支持与关注。


  menu
29 文章
0 浏览
2 当前访客
ღゝ◡╹)ノ❤️

CentOS7.x中Yum方式安装Docker 置顶!

1. 卸载旧的版本

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

2. 安装所需软件

  1. yum-utils 提供了 yum-config-manager

    yum install -y yum-utils

  2. device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2

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

3.设置稳定仓库

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

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

3.清华:yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

4.开始安装程序

1.安装最新版本的 Docker Engine-Community 和 containerd

yum install -y docker-ce docker-ce-cli containerd.io

2.1.安装特定版本的 Docker Engine-Community,列出并排序您存储库中可用的版本,此示例按版本号(从高到低)对结果进行排序。

yum list docker-ce --showduplicates | sort -r

2.2通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。

yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

5.启动 Docker

systemctl start docker

6.运行hello-world

运行 hello-world 映像来验证是否正确

docker run hello-world

7.卸载 Docker 引擎、CLI 和容器包

yum remove docker-ce docker-ce-cli containerd.io

8.删除所有映像、容器和卷:

主机上的映像、容器、卷或自定义配置文件不会自动删除。

rm -rf /var/lib/docker

rm -rf /var/lib/containerd

9.加入开机启动项

1.方式一

ln -s /usr/lib/systemd/system/docker.service /etc/systemd/system/multi-user.target.wants/docker.service

ln -s /usr/lib/systemd/system/containerd.service /etc/systemd/system/multi-user.target.wants/containerd.service

2.方式二

systemctl enable docker.service

systemctl enable containerd.service

10.禁止开机启动

systemctl enable docker.service

systemctl disable containerd.service

11.检查是否加入开机启动项

systemctl list-unit-files|grep docker

systemctl list-unit-files|grep containerd

12.配置拉取镜像加速

腾讯云、163、中国科技大学、阿里云(自己注册)、Dcloud(自己注册)、清华(自己百度)等

vi /etc/docker/daemon.json

内容:

{

"registry-mirrors": [

"https://mirror.ccs.tencentyun.com",

"http://hub-mirror.c.163.com",

"https://docker.mirrors.ustc.edu.cn",

"https://m2adkv7f.mirror.aliyuncs.com"

] }

13.重新加载配置

systemctl daemon-reload


标题:CentOS7.x中Yum方式安装Docker
作者:JayGao
地址:https://www.jaygao.top/articles/2022/03/14/1647246568665.html
版权:版权JayGao所有,如需转载,请注明出处
捐赠: