因为众所周知的缘由,在国内拉取国外的docker镜像时,速度会很慢,甚至失败。好比拉取dotnet core的镜像。
好比如下两个镜像,拉取的时候很是慢html
mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim mcr.microsoft.com/dotnet/core/sdk:3.1-buster
既然是网络缘由,那么就能够经过如下两种方式解决docker
因本人未验证仓库的有效性,这里就不列出来了,可自行搜索关键字docker国内镜像源寻找json
在CentOS中能够经过修改daemon配置文件/etc/docker/daemon.json
来配置bash
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["镜像仓库"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
[root@104 ~]# docker pull mcr.microsoft.com/dotnet/core/sdk:3.1-buster 3.1-buster: Pulling from dotnet/core/sdk d6ff36c9ec48: Pull complete c958d65b3090: Pull complete edaf0a6b092f: Pull complete 80931cf68816: Pull complete 7b9b87089c2a: Pull complete 4f2c2524f197: Pull complete b7b0f8dc0c5c: Pull complete Digest: sha256:1aa53e4fa32dbba836e64e7863955b6b2b165f3a4f8f8aeed648a249300fae07 Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:3.1-buster mcr.microsoft.com/dotnet/core/sdk:3.1-buster
[root@104 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mcr.microsoft.com/dotnet/core/sdk 3.1-buster 9ab567a29502 2 weeks ago 708MB
[root@104 ~]# docker tag 9ab567a29502 registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/sdk:3.1-buster
如上命令,使用tag命令把镜像关联到镜像仓库,用到的参数是image id和仓库地址,而后push服务器
[root@104 ~]# docker push registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/sdk:3.1-buster The push refers to repository [registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/sdk] f506d7422ef0: Layer already exists 5188b84c74d0: Layer already exists 896ff95e1760: Layer already exists e5df62d9b33a: Layer already exists 7a9460d53218: Layer already exists b2765ac0333a: Layer already exists 0ced13fcf944: Layer already exists 3.1-buster: digest: sha256:1aa53e4fa32dbba836e64e7863955b6b2b165f3a4f8f8aeed648a249300fae07 size: 1800
由于个人镜像仓库里已经有了这个镜像,因此不会再次上传网络
把镜像上传好以后,就能够在Dockerfile中使用了,速度超快,以下面的Dockerfileapp
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/sdk:3.1-buster AS build WORKDIR /src COPY ["DockerDemo/DockerDemo.csproj", "DockerDemo/"] RUN dotnet restore "DockerDemo/DockerDemo.csproj" COPY . . WORKDIR "/src/DockerDemo" RUN dotnet build "DockerDemo.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "DockerDemo.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "DockerDemo.dll"]
给出两个dotnet core相关的镜像地址(持续更新)ui
registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/sdk:3.1-buster registry.cn-shenzhen.aliyuncs.com/dotnetcore-vincent/aspnet:3.1-buster-slim registry.cn-shenzhen.aliyuncs.com/rabbitmq-vincent/rabbitmq:3.8.8 registry.cn-shenzhen.aliyuncs.com/dotnet-vincent/sdk:5.0 registry.cn-shenzhen.aliyuncs.com/dotnet-vincent/aspnet:5.0
若有须要下载其余镜像,可留言,本人可帮忙上传到阿里云镜像仓库中this