Newbe.McrMirror 1.1.5 发布,助您全速下载 netcore docker 镜像

2018 年五月之后,微软将后续发布的所有 docker image 都推送到了 MCR (Miscrosoft Container Registry),但在中国大陆,它的速度实在是令人发指,本文将介绍一种方法来解决这个问题。

如何使用

下载方式
 
下载方式

存在至少三种方法进行加速:

  • 使用 docker-mcr (推荐)
  • 拉取国内服务器上的镜像
  • 使用 DockerHub 加速器

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

使用 docker-mcr

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

进入dotnet页面,下载并安装 netcore 3.1 SDK

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

dotnet tool install newbe.mcrmirror -g

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

docker-mcr -i mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim

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

当然,还有更多操作:

下载多个镜像:

docker-mcr --image mcr.microsoft.com/dotnet/core/sdk:3.1,mcr.microsoft.com/dotnet/core/runtime:3.1

从腾讯云下载:

docker-mcr --mirror-host tencentyun --image mcr.microsoft.com/dotnet/core/sdk:3.1

从自定义的服务器下载:

docker-mcr --mirror-host registry.cn-hangzhou.aliyuncs.com --image mcr.microsoft.com/dotnet/core/sdk:3.1 --mirror-namespace newbe36524

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

dotnet tool update newbe.mcrmirror -g

拉取国内服务器上的镜像

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

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

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

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

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

cmd
docker pull registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim
docker tag newbe36524/aspnet:3.1-buster-slim mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim

这样你就成功的在本地得到了 mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim 镜像。

当然,你也可以直接把 registry.cn-hangzhou.aliyuncs.com/newbe36524/aspnet:3.1-buster-slim 写入到你的 Docker file 中。

使用 DockerHub 加速器

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

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

例如,您可以运行以下命令:

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

这样你就成功的在本地得到了 mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim 镜像。

当然,你也可以直接把 newbe36524/aspnet:3.1-buster-slim 写入到你的 Docker file 中。

在此之前,请确保你正确配置了本地的加速器。

更新说明

- 增加了腾讯云服务器的支持

- 增加了docker-mcr 运行命令的中文帮助说明

- 追加支持了超过130个新的镜像 tag

猜你喜欢

转载自www.oschina.net/news/116523/newbe-mcrmirror-1-1-5-released