欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > Docker 安装

Docker 安装

2025/3/19 17:32:20 来源:https://blog.csdn.net/qq_45281820/article/details/140280945  浏览:    关键词:Docker 安装

目录

一,环境准备

二,开始安装

2.1 查询 linux 发行版

2.2 更新系统 RPM包 管理器

2.2.1 dnf RPM 包管理器更新

2.2.2 yum RPM包管理器更新

2.3 安装之前先删除之前的 docker 信息

删除方式一:dnf RPM包管理器执行这个命令:

ERROR: xxx is not in the sudoers file

删除方式二:yum RPM包管理器执行这个命令:

2.4 开始安装 Docker

【2.4.1】安装 Docker 需要的依赖

【2.4.2】 使用 docker 官网将会出现网络连接超时,所以使用阿里云的镜像,命令如下:

【2.4.3】安装 Docker 

【2.4.4】 输入 docker info 

【2.4.5】 启动并设置Docker 开机自启动

2.5 配置 docker 镜像

【2.5.1】vi /etc/docker/daemon.json  # 将下面的镜像内容添加进去

【2.5.2】daemon.json 配置文件修改完成之后,需要重新启动 docker 和 daemon-reload

【2.5.3】拉取 hello-world 镜像

你在实际开发中遇到过类似的问题吗?欢迎在评论区留言交流,一起探讨 Docker 相关的问题! 🚀


一,环境准备

操作系统:AlmaLinux 9

Docker 版本:27.0.3

二,开始安装

2.1 查询 linux 发行版

方式一:

cat /etc/os-release

        这个命令会包含如发行版名称、版本号、ID 等信息

方式二:

lsb_release -a

        这个命令会输出包括发行版描述、版本、代号等详细信息。

2.2 更新系统 RPM包 管理器

        由于小编是使用的是 AlmaLinux 9,AlmaLinux 是一个免费的、开源的、社区驱动的 Linux 发行版,旨在与 Red Hat Enterprise Linux (RHEL) 兼容。它是一个很好的替代 CentOS 的选择,特别是在 CentOS 8 支持结束之后。

        在CentOS 7 时,其系统的 RPM包 管理器主流的是 yum 管理器; 而在CentOS 8 主流使用的是 dnf 管理器。当然CentOS 8 也还是支持 yum ;但是不提倡

        各位看官,可以根据自己的系统来决定。如果是CentOS 7 就更新 yum 管理器,如果是 CentOS 8 就更新 dnf

2.2.1 dnf RPM 包管理器更新

sudo dnf update

        到最后出现 Complete! 编译完成,即表示dnf RPM包管理器更新成功

2.2.2 yum RPM包管理器更新

yum update -y

2.3 安装之前先删除之前的 docker 信息

删除方式一:dnf RPM包管理器执行这个命令:

sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

         小编这边由于使用的不是 root 账号,所以在执行RPM包管理器相关命令的时候需要进行密码认证,如红框框里面那个。如果是 root 账号 则直接执行到 Complete! 编译完成即可!

ERROR: xxx is not in the sudoers file

        如果有同学在执行了sudo 进行 password 认证,之后无法通过抛出一条异常信息:

xxx is not in the sudoers file.  This incident will be reported # 某某用户不在 sudoers 文件范围内。这一事件将被报道

         则需要切换到 root 用户,在最后找到这个 sudoers 文件将自己的用户添加进去即可!命令如下:

切换 root 用户:

[toast@localhost ~]$ su - root  # 切换 root 用户
Password:  # 输入 root 密码
Last login: Mon Jul  8 22:43:21 CST 2024 on pts/0
[root@localhost ~]# 

修改 sudoers 文件,并添加自己的用户信息 

vi /etc/sudoers

         找到 root         ALL=(ALL)         ALL 这条信息,往后面追加一条自己的用户,小编的用户名称是 toast 所以就是:  toast       ALL=(ALL)        ALL

最后别忘记保存  wq!  进行强制退出并保存

        在切换到自己的用户下面,就不会有 xxx is not in the sudoers file.  This incident will be reported 这个错误了。

删除方式二:yum RPM包管理器执行这个命令:

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

2.4 开始安装 Docker

【2.4.1】安装 Docker 需要的依赖

sudo dnf -y install yum-utils

        添加 Docker 需要的RPM包管理器仓库源。下面是使用 docker 官网将会报超时,之所以会超时是有伟大的防火墙保护着我们。 

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

【2.4.2】 使用 docker 官网将会出现网络连接超时,所以使用阿里云的镜像,命令如下:

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

【2.4.3】安装 Docker 

sudo dnf install docker-ce docker-ce-cli containerd.io

        遇到有确认输入[y/N]:直接输入 y 或者 yes 即可;

 

【2.4.4】 输入 docker info 

        当 docker info 可以正常执行,意味着安装成功! 

【2.4.5】 启动并设置Docker 开机自启动

sudo systemctl start docker  #  启动docker
sudo systemctl enable docker #  设置docker 自启动

2.5 配置 docker 镜像

【2.5.1】vi /etc/docker/daemon.json  # 将下面的镜像内容添加进去

{"registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://hub-mirror.c.163.com","https://mirror.baidubce.com"]
}

        小编同学的文件内容如下exec-opts 是小编同学弄 k8s 加上去的,只需要看registry-mirrors的内容即可。

        这个路径下  /etc/docker/daemon.json 默认是没有 daemon.json 这个配置文件的,需要各位看官自己新建一个 daemon.json 配置然后将内容添加进去即可。

【2.5.2】daemon.json 配置文件修改完成之后,需要重新启动 docker 和 daemon-reload

systemctl daemon-reload
systemctl restart docker

【2.5.3】拉取 hello-world 镜像

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:7e1a4e2d11e2ac7a8c3f768d4166c2defeb09d2a750b010412b6ea13de1efb19
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/

        看到有如下内容,表示镜像拉取成功!

        Hello from Docker!
        This message shows that your installation appears to be working correctly.

记得 关注我,后续还会更新更多高质量技术文章!

你在实际开发中遇到过类似的问题吗?
欢迎在评论区留言交流,一起探讨 Docker 相关的问题! 🚀

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词