【Docker学习--1、初了解及安装】

📅 发布时间:2026/8/20 13:07:50
【Docker学习--1、初了解及安装】
一、Docker的生态结构Docker 生态架构的三大组成部分Docker客户端、Docker Host提供容器管理服务)、Registry(镜像仓库)。Docker Daemon : Docker服务端的守护进程用于管理运行的Containers(容器)、镜像、容器的网络等。二、Docker在虚拟机中的安装步骤以Yum源安装为例1、虚拟机环境准备firewall-cmd --state //查看防火墙需要是关闭状态 systemctl stop firewalldsestatus //查看selinux命令状态也需要是disabled。CentOS默认开启的SELinux会限制Docker容器对宿主机文件系统、网络等资源的访问。不关闭的话可能会遇到以下情况容器无法启动Docker守护进程可能因为权限问题无法启动。“ Operation not permitted”错误容器内执行操作时被SELinux策略阻止。数据卷无法访问容器无法读写挂载的宿主机目录。永久关闭的处理方法sudo vi /etc/selinux/config找到SELINUXenforcing这一行将其修改为SELINUXdisabled。保存退出后重启系统sudo reboot。 //重启机器2、获取docker-ce文件 注意点-O 必须大写小写默认是下载进度日志写入wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3、校验查看下载的文件有无问题。可以使用 yum repolist ,如果有软件包出来则无问题如果出现安装的时候有以下错误则很可能是在wget命令的时候-O写成小写了只需删除原 文件后重新执行wget命令即可。[rootlocalhost yum.repos.d]# yum repolist Loaded plugins: fastestmirror, langpacks File contains no section headers. file: file:///etc/yum.repos.d/docker-ce.repo, line: 1 --2026-08-13 00:21:52-- https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo\n4、执行安装命令yum -y install docker-ce如果出现以下报错这个错误的核心原因是CentOS 7 已于 2024年6月30日停止维护EOL官方镜像源mirrorlist.centos.org已不可用所以yum无法找到基础仓库base的软件包列表导致安装 Docker 失败。[rootlocalhost yum.repos.d]# yum -y install docker-ce Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release7archx86_64repoosinfrastock error was 14: curl#6 - Could not resolve host: mirrorlist.centos.org; Unknown error One of the configured repositories failed (Unknown), and yum doesnt have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work fix this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablereporepoid ... 4. Disable the repository permanently, so yum wont use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable repoid or subscription-manager repos --disablerepoid 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setoptrepoid.skip_if_unavailabletrue Cannot find a valid baseurl for repo: base/7/x86_64解决办法思路备份原有 repo 文件可选但建议 bash sudo mv /etc/yum.repos.d/CentOS-Base.rep o /etc/yum.repos.d/CentOS-Base.repo.bak 下载阿里云提供的 CentOS 7 repo 文件 bash sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 如果 curl 不可用可以使用 wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 清除并重建 yum 缓存 bash sudo yum clean all sudo yum makecache 验证基础仓库是否可用 bash yum repolist5、启动docker1、每次启动 systemctl start docker 2、设置开机自启动 systemctl enable docker