ubuntu22 解决docker无法下载镜像问题

server/2024/9/24 8:36:59/

参考在 Ubuntu 中安装 Docker_ubuntu安装docker-CSDN博客

安装docker完成后,运行如下命令验证 Docker 服务是否在运行:

systemctl status docker

运行(sudo docker run hello-world)例子报错:

问题:Docker 无法访问 Docker 注册表(https://registry-1.docker.io/v2/)来下载 hello-world 镜像

解决方案

测试访问 Docker 注册表

        尝试直接访问 Docker 注册表,查看是否有问题。

curl -v https://registry-1.docker.io/v2/

         终端执行上方命令结果:

transky@transky-virtual-machine:~$ curl -v https://registry-1.docker.io/v2/
* Uses proxy env variable no_proxy == 'localhost,127.0.0.0/8,::1'
* Uses proxy env variable https_proxy == 'http://127.0.0.1:7890/'
*   Trying 127.0.0.1:7890...
* Connected to (nil) (127.0.0.1) port 7890 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to registry-1.docker.io:443
> CONNECT registry-1.docker.io:443 HTTP/1.1
> Host: registry-1.docker.io:443
> User-Agent: curl/7.81.0
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 Connection established
< 
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.2 (OUT), TLS header, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.docker.com
*  start date: Sep  2 00:00:00 2024 GMT
*  expire date: Oct  1 23:59:59 2025 GMT
*  subjectAltName: host "registry-1.docker.io" matched cert's "*.docker.io"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M02
*  SSL certificate verify ok.
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
> GET /v2/ HTTP/1.1
> Host: registry-1.docker.io
> User-Agent: curl/7.81.0
> Accept: */*
> 
* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< content-type: application/json
< docker-distribution-api-version: registry/2.0
< www-authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"
< date: Mon, 23 Sep 2024 08:00:28 GMT
< content-length: 87
< strict-transport-security: max-age=31536000
< 
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}
* Connection #0 to host (nil) left intact

         curl 命令能够成功,因为它使用了代理  http://127.0.0.1:7890/

        * Uses proxy env variable https_proxy == 'http://127.0.0.1:7890/'

        这意味着您设置了 http_proxyhttps_proxy 的环境变量,指向了本地代理。

Docker 未使用代理

  • Docker 命令失败的原因是 Docker 未配置使用您的代理设置。
  • 默认情况下,Docker 不会继承环境变量中的代理设置,如 http_proxyhttps_proxy

解决方法:

需要配置 Docker 以使用您的代理设置。以下是步骤:

创建 Docker systemd 服务目录

sudo mkdir -p /etc/systemd/system/docker.service.d

创建代理配置文件

sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf

添加代理设置

        在文件中,添加以下内容(请根据需要替换代理地址和端口):

[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890/"
Environment="HTTPS_PROXY=http://127.0.0.1:7890/"
Environment="NO_PROXY=localhost,127.0.0.1"

重新加载 systemd 配置并重启 Docker

sudo systemctl daemon-reload
sudo systemctl restart docker

验证 Docker 是否使用了代理

        再次运行 Docker 命令:

sudo docker run hello-world

        如果配置正确,应该可以成功拉取镜像。

最终测试(sudo docker run hello-world)结果:

transky@transky-virtual-machine:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:91fb4b041da273d5a3273b6d587d62d518300a6ad268b28628f74997b93171b2
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/


http://www.ppmy.cn/server/121259.html

相关文章

Sentinel-1 数据处理时如何手动下载高程数据

在Sentinel-1 数据数据预处理时&#xff0c;会使用高程数据进行地形校正。但选择自动下载高程时&#xff0c;由于网络原因经常会卡死&#xff0c;造成预处理过程不能正常进行&#xff01; 这个问题经过我的反复实践&#xff0c;可以通过手动下载高程数据来解决。下面是具体方法…

使用IDA Pro动态调试Android APP

版权归作者所有&#xff0c;如有转发&#xff0c;请注明文章出处&#xff1a;https://cyrus-studio.github.io/blog/ 关于 android_server android_server 是 IDA Pro 在 Android 设备上运行的一个调试服务器。 通过在 Android 设备上运行android_server&#xff0c;IDA Pro …

C++(学习)2024.9.20

目录 C面向对象的基础知识 this指针 概念 功能 1.类内调用成员 2.区分重名的成员变量和局部变量 3. 链式调用 static关键字 1.静态局部变量 2.静态成员变量 3.静态成员函数 4.单例设计模式 const关键字 1.const修饰成员函数 2.const修饰对象 3.const修饰成员变量…

GNU链接器(LD):输入分区和输出分区介绍

0 参考资料 GNU-LD-v2.30-中文手册.pdf GNU linker.pdf1 前言 一个完整的编译工具链应该包含以下4个部分&#xff1a; &#xff08;1&#xff09;编译器 &#xff08;2&#xff09;汇编器 &#xff08;3&#xff09;链接器 &#xff08;4&#xff09;lib库 在GNU工具链中&…

[vulnhub] Hackademic.RTB1

第一次打靶机&#xff0c;思路看的红队笔记 https://www.vulnhub.com/entry/hackademic-rtb1,17/ 环境&#xff1a;kali Linux - 192.168.75.131&#xff0c;靶机 - 192.168.75.132 主机发现和端口扫描 扫描整个网络有哪台机子在线&#xff0c;不进行端口扫描 nmap -sP 192.16…

漏洞挖掘 | Selenium Grid 中的 SSRF

Selenium 网格框架上的基本服务器端请求伪造 最近&#xff0c;我正在阅读漏洞文章看到Peter Jaric写的一篇 Selenium Grid 文章&#xff1b;他解释了 Selenium Grid 框架上缺乏身份验证和安全措施强化的问题。 在网上进行了更多搜索&#xff0c;我发现 Selenium Grid 开箱即用…

Webpack 常见配置项

1. entry 指定一个或多个入口点&#xff0c;Webpack 从这里开始构建依赖图。 entry: {main: ./src/index.js,admin: ./src/admin.js }2. output 指定输出文件的路径和名称。 output: {filename: [name].bundle.js,path: path.resolve(__dirname, dist),publicPath: /assets…

通过深度学习识别情绪

通过深度学习识别情绪&#xff08;Emotion Recognition using Deep Learning&#xff09;是一项结合多模态数据的技术&#xff0c;旨在通过分析人类的面部表情、语音语调、文本内容等特征来自动识别情绪状态。情绪识别在人机交互、健康监测、教育、娱乐等领域具有广泛的应用。 …