Server - 服务器 CentOS 安装与配置 Docker

欢迎关注我的CSDN:https://spike.blog.csdn.net/

本文地址:https://spike.blog.csdn.net/article/details/159988565

免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。


在 CentOS 上安装与配置 Docker 的核心流程主要包括环境修复、组件安装和网络优化。由于 CentOS 7 已停更,首先需将系统基础 yum 源替换为阿里云历史存档源,以解决依赖下载报错问题。接着,添加 Docker 的国内仓库并安装最新版核心组件,配置服务开机自启。最后,为避免拉取官方镜像超时,必须在配置文件中添加国内镜像加速器并重启服务,即可完成稳定 Docker 环境的搭建。

1. 修改 Docker 配置

安装依赖:

bash 复制代码
# 1. 备份原有的 yum 源配置文件(以防万一)
sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
sudo mkdir -p /etc/yum.repos.d/bak
sudo mv /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/bak/

# 2. 下载阿里云的 CentOS 7 基础源
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# 3. 将源地址替换为 Vault 存档源(因为普通镜像节点也已清理了 CentOS 7 的数据)
sudo sed -i 's/mirrors.aliyun.com\/centos/mirrors.aliyun.com\/centos-vault/g' /etc/yum.repos.d/CentOS-Base.repo
sudo sed -i 's/$releasever/7.9.2009/g' /etc/yum.repos.d/CentOS-Base.repo

清空缓存:

bash 复制代码
sudo yum clean all
sudo yum makecache

2. 安装 Docker

执行安装 Docker 命令:

bash 复制代码
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

配置 Docker:

bash 复制代码
sudo systemctl start docker
sudo systemctl enable docker

3. 配置 Docker 源

添加镜像加速器:

bash 复制代码
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://docker.1panel.live",
    "https://hub.rat.dev",
    "https://dockerpull.com",
    "https://docker.anyhub.us.kg"
  ]
}
EOF

重启配置:

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

验证是否安装成功:

bash 复制代码
sudo docker run hello-world

输出:

bash 复制代码
Hello 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 the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share 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/

Docker 版本:

bash 复制代码
# docker --version
Docker version 26.1.4, build 5650f9b
相关推荐
tedcloud1231 小时前
OpenShip 部署指南:开源 AI 应用快速启动模板 Linux 搭建实践
linux·运维·服务器·人工智能·开源
微学AI1 小时前
内网穿透的应用-服务器日志出现异常怎么办?Python监控、钉钉告警与远程处理教程
服务器·python·钉钉
土星云SaturnCloud9 小时前
边缘侧大模型部署的新利器——国科环宇GK 300I大模型一体机深度评测与架构解析
服务器·人工智能·ai·边缘计算
晚风吹长发10 小时前
Docker基础——Docker Network(网络详解)
linux·运维·网络·ubuntu·docker·容器
Cx330_FCQ10 小时前
Tmux使用
服务器·git·算法
高磊200511 小时前
LVS(Linux virual server)
linux·服务器·lvs
山峰哥12 小时前
数据库性能救星:Explain执行计划深度拆解
服务器·开发语言·数据库·sql·启发式算法
aramae14 小时前
C++ IO流完全指南:从C标准库到C++流式编程
服务器·c语言·开发语言·c++·后端
ji_shuke14 小时前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
M哥支付16 小时前
什么是收付一体模式?
服务器·网络·其他·微信·金融