配置国内 DNS
你可以编辑 /etc/dhcpcd.conf 文件,指定国内的 DNS 服务器。
步骤:
编辑 dhcpcd.conf 配置文件:
bash
复制
编辑
sudo nano /etc/dhcpcd.conf
找到 interface wlan0 部分,然后修改为以下内容,指定阿里云的 DNS:
bash
复制
编辑
interface wlan0
static domain_name_servers=223.5.5.5 223.6.6.6
或者使用腾讯云 DNS:
bash
复制
编辑
interface wlan0
static domain_name_servers=119.29.29.29 182.254.116.116
保存并退出编辑器(按 Ctrl + X,然后按 Y,再按 Enter)。
重新启动树莓派:
bash
复制
编辑
sudo reboot
重新尝试更新:
bash
复制
编辑
sudo apt-get update
总结
阿里云 DNS:223.5.5.5 和 223.6.6.6
腾讯云 DNS:119.29.29.29 和 182.254.116.116
百度 DNS:180.76.76.76
这些是国内常用的 DNS 服务器,替换后,树莓派将会使用更快的 DNS 解析服务。
从你提供的信息来看,配置中科大镜像加速器时出现了问题,导致 Docker 仍然尝试从 registry-1.docker.io
拉取镜像,而不是使用配置的镜像加速器。这可能是由于配置文件中存在语法错误或格式问题。
修正配置文件
请确保 /etc/docker/daemon.json
文件的格式正确。以下是正确的配置步骤:
-
创建或编辑
/etc/docker/daemon.json
文件:
sudo mkdir -p /etc/docker
sudo nano /etc/docker/daemon.json
```
-
在文件中添加以下内容:
{ "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] }
{ "registry-mirrors": [ "https://hub.nat.tf", "https://hub1.nat.tf", "https://hub2.nat.tf", "https://docker.1panel.live", "https://docker.m.daocloud.io", "https://alzgoonw.mirror.aliyuncs.com", "https://cr.console.aliyun.com/", "https://mirror.ccs.tencentyun.com", "https://dockerproxy.com", "https://docker.nju.edu.cn" ] }
确保 JSON 格式正确,没有多余的引号或括号。
保存并关闭文件。
-
重新加载 Docker 配置并重启 Docker 服务:
<header data-v-d3e67ab0="" class="segment-code-header" style="margin: 0px; padding: 0px 0px 0px 12px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: 14px; line-height: inherit; font-family: inherit; font-optical-sizing: inherit; font-size-adjust: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; vertical-align: baseline; display: flex; height: 36px; background-color: var(--code-header-bg); border-top-left-radius: 12px; border-top-right-radius: 12px; align-items: center; position: sticky; z-index: 1; top: 46px; left: 0px;">bash复制</header>
sudo systemctl daemon-reload sudo systemctl restart docker
验证配置是否生效
运行以下命令,检查 Docker 是否使用了配置的镜像加速器:
sudo systemctl status docker
在输出中,你应该能看到类似以下内容,表明 Docker 已经加载了配置文件:
`Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)`
### 再次尝试拉取镜像
运行以下命令,尝试拉取 `hello-world` 镜像:
docker run hello-world