CentOS系统安装Docker
###yum源配置###
wget -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# wget、curl两种下载方式皆可
yum clean all #清理yum缓存
yum makecache #重新加载缓存
###准备工作###
systemctl disable firewalld #关闭防火墙,disable关闭开机自启动、stop立即关闭
systemctl stop firewalld
yum remove docker* #卸载旧版本,安装关联环境
yum install -y yum-utils
###安装Docker###
yum install docker* -y #安装docker
systemctl start docker #启动docker
docker version #检查版本和状态
docker run hello-world #Hello-world,运行测试镜像
docker image #查看hello-world镜像
###开启内核转发流量###
Docker 在默认情况下使用 Linux 内核的网络命名空间和网络桥接技术来创建容器的网络环境。
开启内核流量转发,以确保容器内部的网络流量能够正确地转发到宿主机和其他网络设备。
cat << EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/docker.conf
###配置docker镜像加速###
docker镜像源默认配置国外资源,配置国内镜像加速源,提高下载速率。
配置daemon.json文件,注意json文件格式,格式不正确会导致启动docker进程失败。
mkdir -p /etc/docker
cat << EOF> /etc/docker/daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
}
EOF
systemctl daemon-reload #重新加载配置文件,重启docker进程
systemctl enable docker
systemctl restart docker
docker info #查看是否应用成功
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~