解决Docker在pull的时候报错Get https://registry-1.docker.io/v2/: net/http: request can...

目录

问题:

解决步骤

        步骤一: 修改 Docker 配置文件

        步骤二: 重启 Docker 服务

问题:

docker-compose up -d neo4j

        出现报错:

        ERROR: Get "https://registry-1.docker.io/v2/": dial tcp 47.88.58.234:443: connect: connection refused
 找了很多国内的镜像都没有解决

解决步骤

        步骤一: 修改 Docker 配置文件

        打开终端,使用文本编辑器打开 Docker 配置文件:

sudo vi /etc/docker/daemon.json

   按下:“i” :  插入

将以下内容添加到配置文件中:

{
  "registry-mirrors" : [
    "https://docker.registry.cyou",
    "https://docker-cf.registry.cyou",
    "https://dockercf.jsdelivr.fyi",
    "https://docker.jsdelivr.fyi",
    "https://dockertest.jsdelivr.fyi",
    "https://mirror.aliyuncs.com",
    "https://dockerproxy.com",
    "https://mirror.baidubce.com",
    "https://docker.m.daocloud.io",
    "https://docker.nju.edu.cn",
    "https://docker.mirrors.sjtug.sjtu.edu.cn",
    "https://docker.mirrors.ustc.edu.cn",
    "https://mirror.iscas.ac.cn",
    "https://docker.rainbond.cc",
    "https://do.nark.eu.org",
    "https://dc.j8.work",
    "https://dockerproxy.com",
    "https://gst6rzl9.mirror.aliyuncs.com",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "http://mirrors.ustc.edu.cn/",
    "https://mirrors.tuna.tsinghua.edu.cn/",
    "http://mirrors.sohu.com/"
  ],
  "insecure-registries" : [
    "registry.docker-cn.com",
    "docker.mirrors.ustc.edu.cn"
  ],
  "debug": true,
  "experimental": false
}
        步骤二: 重启 Docker 服务
sudo systemctl restart docker

最终成功!(ps:  如果不行,切换热点试一下,我是用的4G联通热点)

### 访问Docker Hub注册表API 为了成功访问 Docker Hub 注册表 API `https://registry-1.docker.io/v2/`,需要确保网络连接稳定并配置好必要的认证信息。当遇到错误提示类似于 `net/http: request canceled` 时,这通常意味着请求被取消或超时,可能是由于网络不稳定或是未设置合适的镜像源造成的[^1]。 对于 Windows 用户来说,在尝试通过命令行工具或其他 HTTP 客户端发送请求之前,建议先验证本地环境是否能够正常解析域名以及是否有可用的互联网连接。如果确实存在上述提到的问题,则可以考虑调整 Docker 的配置文件来指定国内加速器地址作为镜像仓库的代理服务器之一: ```json { "registry-mirrors": [ "https://docker.211678.top", "https://docker.1panel.live", "https://hub.rat.dev", "https://docker.m.daocloud.io", "https://do.nark.eu.org", "https://dockerpull.com", "https://dockerproxy.cn", "https://docker.awsl9527.cn" ] } ``` 此 JSON 片段展示了如何修改 Docker 配置以利用多个中国境内的镜像站点提高下载速度和成功率[^2]。请注意,具体路径取决于操作系统版本;对于 Windows,默认情况下该文件位于 `%programdata%\docker\config\daemon.json` 中。 另外,要直接向 Docker Registry 发送 API 请求,还需要遵循官方文档中的指导完成身份验证过程。一般而言,可以通过获取 OAuth2 Token 或者 Basic Auth 凭证的方式来进行授权操作。下面是一个简单的 Python 脚本例子展示怎样使用 requests 库执行带认证的信息查询: ```python import base64 import json import requests def get_auth_token(username, password): auth_string = f'{username}:{password}' encoded_credentials = base64.b64encode(auth_string.encode('ascii')).decode('utf-8') headers = { 'Authorization': f'Basic {encoded_credentials}', 'Content-Type': 'application/json' } url = 'https://index.docker.io/v1/auth' response = requests.get(url=url, headers=headers) if response.status_code != 200: raise Exception(f"Failed to authenticate with status code {response.status_code}") token_data = response.json() return token_data['token'] if __name__ == '__main__': username = input("Enter your Docker ID:") password = input("Enter your Password:") try: token = get_auth_token(username=username, password=password) print(token) except Exception as e: print(e) ``` 这段代码实现了基本的身份验证流程,并打印出了获得的令牌。实际应用中应当妥善保管这些敏感数据而不是硬编码在脚本里。此外,考虑到安全性因素,推荐采用更安全的方法如 OAuth2 来代替明文传输用户名密码组合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值