Kubernetes需要使用docker作为运行时,在Linux机器上安装docker后,尝试拉取hello-world
镜像时出现问题
安装docker时一切都很顺利:
sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
但在进行docker pull hello-world
拉取镜像时报错:
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceed ed while awaiting headers)
解决方法
首先需要更换docker源,这里使用阿里云镜像加速器与另一个自己收集的源。进入/etc/docker/daemon.json
文件中如此配置:
{
"registry-mirrors": [
"https://ok5mwqnl.mirror.aliyuncs.com",
"https://docker.1ms.run"
]
}
配置完成后执行sudo systemctl restart docker
重启docker服务
重启后运行docker pull hello-world
仍失败,报错信息与先前一致
这时考虑DNS配置问题,进入/etc/resolv.conf
文件,在原有的若干nameserver
之上再增加两条:
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4
# 此处为原有的若干行nameserver
# ...
配置完成后运行docker pull hello-world
,成功拉取镜像,执行sudo docker images
查看本地镜像:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest ee301c921b8a 20 months ago 9.14kB
之后可以使用docker run hello-world
创建容器并运行,也可以使用docker rmi ee301c921b8a
删除该镜像
参考
ubuntu20.04安装Kubernetes(k8s 1.27.4)