破浪前行的一条鱼 博客

Docker系列--2.Docker拉取.Net Core运行环境太慢

说明

  • 因为使用Docker编译.Net Core时需要拉取微软官方镜像,但是下载又很慢。你懂的!!
  • 参考了下大佬们的思路,大概是用一台国外vps(本人使用的是阿里云国内好像拉取速度也还可以)把镜像拉取到本地,然后push到阿里云或者腾讯云的私有仓储,然后使用 docker tag 标记
  • 以下是制作的私有镜像公开的.Net Core 2.2镜像地址,可直接使用。

    • 运行环境
      registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim
    • SDK
      registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:sdk-2.2-stretch

步骤

  1. 登录你的vps
  2. pull拉取镜像
  3. 本地tag标记
  4. push私有仓储
  5. 使用时在虚拟机或者其他机子pull私有仓储

详细步骤

1、登录vps 然后拉取 等待拉取完成

[root@myserver ~]# docker pull mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim
2.2-stretch-slim: Pulling from dotnet/core/aspnet
804555ee0376: Pull complete 
970251047358: Pull complete 
f3d4c41a4fd1: Pull complete 
bd391c46585f: Pull complete 
Digest: sha256:ae9a94a778b4c4656f036e1dd858d6c972f6ad4423bdf9c5022e16f28fee5cf9
Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim
mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim

2、查看并push私有仓储

  • 以下是阿里云私有仓储push教程,其他私有仓储请按照相应云服务商教程来
--查看拉取成功后的镜像
[root@myserver ~]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/dotnet/core/aspnet   2.2-stretch-slim    e7e3b238011c        7 months ago        261MB

--按照私有仓储教程push 
[root@myserver ~]# docker tag e7e3b238011c registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim
[root@myserver ~]# docker images
REPOSITORY                                                              TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/dotnet/core/aspnet                                    2.2-stretch-slim    e7e3b238011c        7 months ago        261MB
registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore   2.2-stretch-slim    e7e3b238011c        7 months ago        261MB
-- 执行push 上传
[root@myserver ~]# docker push registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim
The push refers to repository [registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore]
579a8f1d6a12: Pushed 
15e45d99c926: Pushed 
0cf75cb98eb2: Pushed 
814c70fdae62: Pushed 
2.2-stretch-slim: digest: sha256:ae9a94a778b4c4656f036e1dd858d6c972f6ad4423bdf9c5022e16f28fee5cf9 size: 1164

--上传成功

3、使用镜像

-- 按照云服务商私有镜像拉取
[root@localhost docker_mvc]# docker pull registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim
2.2-stretch-slim: Pulling from polang_dotnetcore/polang_dotnetcore
Digest: sha256:ae9a94a778b4c4656f036e1dd858d6c972f6ad4423bdf9c5022e16f28fee5cf9
Status: Image is up to date for registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim
registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore:2.2-stretch-slim

-- 使用tag标记
[root@localhost docker_mvc]# docker images  --查看下载成功的私有镜像
REPOSITORY                                                              TAG                 IMAGE ID            CREATED             SIZE
registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore   2.2-stretch-slim    e7e3b238011c        7 months ago        261MB
[root@localhost docker_mvc]# docker tag e7e3b238011c mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim   --使用tag标记
[root@localhost docker_mvc]# docker images  --再次查看
REPOSITORY                                                              TAG                 IMAGE ID            CREATED             SIZE
mcr.microsoft.com/dotnet/core/aspnet                                    2.2-stretch-slim    e7e3b238011c        7 months ago        261MB
registry.cn-shenzhen.aliyuncs.com/polang_dotnetcore/polang_dotnetcore   2.2-stretch-slim    e7e3b238011c        7 months ago        261MB

参考

docker-mcr 助您全速下载 dotnet 镜像

Docker tag 命令

本原创文章未经允许不得转载 | 当前页面:破浪前行的一条鱼 博客 » Docker系列--2.Docker拉取.Net Core运行环境太慢

评论