docker报错-无法连接到 Docker Hub 仓库

问题

执行linux命令docker run hello-world,结果报无法连接到docker仓库或者超时的错误,如图

解决

修改docker的仓库镜像源,修改/etc/docker/daemon.json文件。如果在/etc/docker下找不到daemon.json文件,就创建该文件,配置如下

bash 复制代码
{
  #增加registry-mirrors镜像源
  "registry-mirrors": ["https://docker.m.daocloud.io"],
  "insecure-registries" : [
    "docker-registry.zjq.com"
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "10"
  },
  "data-root": "/usr/local/env/rabbitmq/data"
}

再执行systemctl restart docker命令,重新启动docker,然后执行docker info命令,就可以看到docker的镜像源已经被修改成功

bash 复制代码
Client: Docker Engine - Community
 Version:    26.1.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 26.1.3
 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: 8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 4.18.0-147.el8.x86_64
 Operating System: CentOS Linux 8 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 1.764GiB
 Name: localhost.localdomain
 ID: b775db5b-a895-4701-881e-e190b8344ebd
 Docker Root Dir: /usr/local/env/rabbitmq/data
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  docker-registry.zjq.com
  127.0.0.0/8
 Registry Mirrors:
  https://docker.m.daocloud.io/
 Live Restore Enabled: false

重新执行docker run hello-world命令就可以得到如图

bash 复制代码
17eec7bbc9d7: Pull complete 
Digest: sha256:f7931603f70e13dbd844253370742c4fc4202d290c80442b2e68706d8f33ce26
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
相关推荐
木童6621 小时前
Ruo-Yi 项目 CICD 完整部署文档(含命令详解)
ci/cd·docker·容器
幺零九零零2 小时前
Docker底层- 命令详解
运维·docker·容器
网络风云4 小时前
Flask 的 Docker 部署指南
python·docker·flask
Ama_tor4 小时前
docker|F盘安装の1键部署软件及数据储存+2个保姆级运行实例
运维·docker·容器
可爱又迷人的反派角色“yang”4 小时前
GitLab配置与git集成实践
linux·网络·git·docker·云计算·gitlab
invicinble6 小时前
对于docker在项目中的完整实战
运维·docker·容器
❀͜͡傀儡师7 小时前
Docker快速部署一个轻量级邮件发送 API 服务
jvm·docker·容器
深耕AI7 小时前
Docker Volumes详解
运维·docker·容器
Bypass--7 小时前
防护篇 | 云原生安全攻防实战
安全·云原生·容器·kubernetes
山外山与楼外楼8 小时前
微服务虾谈
docker·微服务·容器