Docker安装、配置代理

国内Docker镜像源切换与CgroupDriver修改指南
本文介绍了如何在Linux系统中将Docker的镜像源更改为国内镜像源(如DockerProxy、网易、百度、腾讯),以及将CgroupDriver从cgroupfs修改为Systemd以优化Kubernetes环境。步骤包括编辑daemon.json文件并重启docker服务进行验证。

一、安装 docker-ce docker-compose-plugin

rocky

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-compose-plugin
systemctl enable --now docker

Ubuntu

apt update
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install -y docker-ce docker-compose-plugin
systemctl enable --now docker 

二、配置代理

2024.9更新,dockerhub还是连不上,自己配置代理来拉取镜像比较靠谱,这里需要提前准备梯子 。。
官方建议新建配置文件 /etc/systemd/system/docker.service.d/http-proxy.conf
新增Environment来实现代理。

这里直接修改docker.service文件了

# vim /lib/systemd/system/docker.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=xxxx.com,127.0.0.1,localhost"  
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
  • NO_PROXY 是绕过代理服务器直连 这里可以是自己的镜像源、或者本地IP等

三、验证

以上两个修改都需要重启docker服务

$ systemctl daemon-reload
$ systemctl restart docker

验证

$ docker info

有以下回显就成功了。

HTTP Proxy: http://127.0.0.1:7890
HTTPS Proxy: https://127.0.0.1:7890

测试拉取镜像:

root@u24:~# docker pull mysql:8.0.37
8.0.37: Pulling from library/mysql
7af76bb36546: Pull complete 
0991eb3c93d6: Pull complete 
ee250fe5d1f7: Pull complete 
0333fe8b06fc: Pull complete 
a37b576bcdc3: Pull complete 
fd5e573b6b09: Pull complete 
2797560be722: Pull complete 
5bab8feae9ff: Pull complete 
c68d02817e28: Pull complete 
ac2c5b495768: Pull complete 
903730759b43: Pull complete 
Digest: sha256:598bf8b783dddc9070e9011aeb1eb5947f0bf7c4eda8ac510906556b8a2b6d0a
Status: Downloaded newer image for mysql:8.0.37
docker.io/library/mysql:8.0.37

四、提示 bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

需要修改内核参数,开启ip转发功能,
br_netfilter模块用于将桥接流量转发至iptables链,开启br_netfilter模块即可转发。

# 设置所需的 sysctl 参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/docker.conf
#net.bridge.bridge-nf-call-iptables  = 1
#net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
sysctl -p

#确认 br_netfilter 模块被加载
lsmod | grep br_netfilte

# 确认 net.ipv4.ip_forward 系统变量在你的 sysctl 配置中被设置为 1:
sysctl net.ipv4.ip_forward

# 重启docker
systemctl restart docker 
docker info
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值