欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > 如何解决 Docker 下载 mcr.microsoft.com 镜像慢的办法

如何解决 Docker 下载 mcr.microsoft.com 镜像慢的办法

2024/10/25 21:16:41 来源:https://blog.csdn.net/zhy810302/article/details/142648759  浏览:    关键词:如何解决 Docker 下载 mcr.microsoft.com 镜像慢的办法

一、介绍

    MCR(Miscrosoft Container Registry) 加速器,助你在中国大陆急速下载 netcore 相关的 docker 镜像。

二、解决办法。

    1、如何使用

      至少三种方法进行加速:
        使用 docker-mcr (推荐)
        拉取国内服务器上的镜像
        使用 DockerHub 加速器

      注意,无论采用什么方式,请先确保本地的 docker 已经正常可用。

    2、使用 docker-mcr (推荐)

      docker-mcr 是一个 dotnet core global tool,简单几步,便可以进行安装和使用。

      进入 dotnet 页面,下载并安装 netcore 3.1 SDK 或者 Net 5.0,如果没有安装 SDK,是无法使用 dotnet 命令的。

      



      安装完毕后打开控制台运行以下命令:

#dotnet tool install newbe.mcrmirror -g

     如果已经安装,会提示已经安装。
      


      现在,假如需要拉取 mcr.microsoft.com/dotnet/aspnet:3.1-buster-slim ,则运行以下命令:#docker-mcr -i mcr.microsoft.com/dotnet/aspnet:3.1-buster-slim
      


      等待完成之后,便可以在本地看到已经拉取完毕的镜像。
      


      您可以运行 docker-mcr --help 来查看更多的参数配置方式。

      命令:#docker-mcr --help
      



      如果您曾经安装过 newbe.mcrmirror,您需要使用 dotnet tool update newbe.mcrmirror -g命令来进行升级,确保最佳的体验。

      命令:#dotnet tool update newbe.mcrmirror -g
      


 

    3、拉取国内服务器上的镜像

      加速的本质是因为我将镜像推送到了国内的服务器,目前在以下服务器均存在镜像:

            阿里云:registry.cn-hangzhou.aliyuncs.com/newbe36524
            腾讯云:ccr.ccs.tencentyun.com/mcr_newbe36524

      以下以阿里云为例进行说明,假设需要拉取 【aspnet:3.1-buster-slim】 和【sdk:3.1-buster】

      则拼接上面的前缀,则得到地址【registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim】 和【registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:3.1-buster】 。

      然后,为了不修改默认的 Dockerfile 您可以运行以下命令:
 

3.1 版本
#docker pull registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim
#docker tag registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim5         
#docker pull registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:3.1-buster
#docker tag registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:3.1-buster mcr.microsoft.com/dotnet/core/sdk:3.1-buster

ASP.NET 3.1 镜像
       


        



ASP.NET SDK 3.1 镜像
        

       

这样你就成功的在本地得到了 【mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim】和【mcr.microsoft.com/dotnet/core/sdk:3.1-buster】 镜像。
       当然,你也可以直接把 【registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim】和【registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:3.1-buster】 写入到你的 Docker file 中。

5.0 版本#docker pull registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:5.0-buster-slim
#docker tag registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:5.0-buster-slim mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim
#docker pull registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:5.0-buster-slim
#docker tag registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:5.0-buster-slim mcr.microsoft.com/dotnet/core/sdk:5.0-buster-slim

ASPNET SDK 5.0 镜像        
        

       


        

        
      
       这样你就成功的在本地得到了【mcr.microsoft.com/dotnet/core/aspnet:5.0-buster-slim】 和 【mcr.microsoft.com/dotnet/core/sdk:5.0-buster-slim】 镜像。
       当然,你也可以直接把 【registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:5.0-buster-slim】 和 【registry.cn-hangzhou.aliyuncs.com/newbe36524/sdk:5.0-buster-slim】写入到你的 Dockerfile 中。


    4、使用 DockerHub 加速器(这个开始有点慢)

      我也将镜像推送到了 DockerHub ,所以正常来说,在中国大陆使用 DockerHub 加速器也可以达到加速的效果。

      规则,mcr.microsoft.com/dotnet/cre/{name}:{tag} -> newbe36524/{name}:{tag}

      ASP.NET 3.1 镜像

        【1】、命令:#docker pull newbe36524/aspnet:3.1-buster-slim

            



        【2】、命令:#docker tag newbe36524/aspnet:3.1-buster-slim mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim

            



        【3】、命令:#docker images

            


 

复制代码

1       #docker pull newbe36524/aspnet:3.1-buster-slim
2       #docker tag newbe36524/aspnet:3.1-buster-slim mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim


 3       #docker pull newbe36524/sdk:3.1-buster
  4           #docker tag newbe36524/sdk:3.1-buster mcr.microsoft.com/dotnet/core/sdk:3.1-buster

复制代码


      ASP.NET 3.1 镜像
        
        【1】、命令:#docker pull newbe36524/sdk:3.1-buster
        
            



        【2】、命令:#docker tag newbe36524/sdk:3.1-buster mcr.microsoft.com/dotnet/core/sdk:3.1-buster
        
            



        【3】、命令:#docker images

            




      这样你就得到了【mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim】和【mcr.microsoft.com/dotnet/core/sdk:3.1-buster】 镜像。当然,你也可以直接把 【newbe36524/aspnet:3.1-buster-slim】和【newbe36524/sdk:3.1-buster】 写入到你的 Dockerfile 中。在此之前,请确保你正确配置了本地的加速器。

【参考文章】解决 Docker 下载 mcr.microsoft.com 镜像慢的办法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com