安装完docker,拉取镜像报错Unable to find image ‘hello-world:latest‘ locallydocker: Error response from daemon

安装完docker后测试是否成功安装,拉取hello-world镜像进行测试

报以下错误

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
 

刚开始以为是权限问题

直接把daemon.json文件加权限 ,还是报错

[root@localhost docker]# chmod 777 daemon.json 
[root@localhost docker]# sudo systemctl daemon-reload
[root@localhost docker]# sudo systemctl restart docker
[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp 108.160.166.137:443: i/o timeout (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
 

在网上搜了几种方法,基本都是镜像源的问题,我这里已经添加了阿里云的镜像源,还是会报这个错误,尝试使用其他镜像源

[root@localhost docker]# cat daemon.json 
{
    "registry-mirrors": [
        "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
更改完镜像源后,重启docker进行重新拉取hello-world,发现还是报错

此时进行docker info进行查看,发现有个报错

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

于是进行解决这个报错

[root@localhost docker]# docker info
Client: Docker Engine - Community
 Version:    26.1.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 26.1.4
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-693.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.781GiB
 Name: localhost.localdomain
 ID: ac6faaa2-00de-445a-b6e0-7fba22e5a500
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://do.nark.eu.org/
  https://dc.j8.work/
  https://docker.m.daocloud.io/
  https://dockerproxy.com/
  https://docker.mirrors.ustc.edu.cn/
  https://docker.nju.edu.cn/
 Live Restore Enabled: false

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

做一下修改和配置来解决这个问题。

由于将linux系统作为路由或者VPN服务就必须要开启IP转发功能。当linux主机有多个网卡时一个网卡收到的信息是否能够传递给其他网卡,如果设置成1的话可以进行数据包转发,可以实现VxLAN等功能,不开启会导致docker部署应用无法访问。

1.开启包转发功能和修改内核参数

br_netfilter模块用于将桥接流量转发至iptables链,br_netfilter内核参数则需要开启转发。

执行以下命令:

[root@localhost docker]# modprobe br_netfilter

[root@localhost docker]# cat > /etc/sysctl.d/docker.conf <<EOF
> net.bridge.bridge-nf-call-ip6tables=1
> net.bridge.bridge-nf-call-iptables = 1
> net.ipv4.ip_forward = 1
> EOF

重新加载使配置生效
[root@localhost docker]# sysctl -p /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1

查看配置是否生效
[root@localhost docker]# lsmod | grep br_netfilter
br_netfilter           22209  0 
bridge                136173  1 br_netfilter

当重启Docker后以上模块配置会失效,为确保下次重启后依然生效,可设置开机自动加载模块的脚本。

首先,在/etc/目录下新建rc.sysinit文件,输入命令:vim /etc/rc.sysinit,然后再编辑器界面输入一下命令:

[root@localhost docker]# vim /etc/rc.sysinit

#!/bin/bash
for file in /etc/sysconfig/modules/*.modules ; do
[ -x $file ] && $file
done

在/etc/sysconfig/modules/目录下新建文件br_netfilter.modules
[root@localhost docker]# cd /etc/sysconfig/modules/
[root@localhost modules]# ls
[root@localhost modules]# vim br_netfilter.modules

modprobe be_netfilter

给 br_netfilter.modules文件授权
[root@localhost modules]# chmod 755 /etc/sysconfig/modules/br_netfilter.modules 
[root@localhost modules]# systemctl restart docker
再次docker info 发现报错信息已经没了

再次docker run hello-world进行拉取镜像,发现解决了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值