This article has been included GitHub There are also Internet factory interview questions, interview strategies, efficient learning materials and so on
Docker is cool to use, especially when used in DevOps practice.However, when you pull a mirror at home or locally, you often encounter constipation - either slowly or intermittently, or the connection timed out!
It's a nightmare when we have a big mirror (like someone losing a Warcraft bag in their code)!So how do you solve this problem?Next, we will solve this problem mainly from the following aspects:
- Using Mirror Accelerators
- Source Change
- Make your own mirror and push it to domestic warehouse
- Build your own near mirror warehouse
- Last trick (confidentiality)
2. Mirror Accelerators
Accelerators can be sacrificed for playing online game cards. Mirror-pulling commonly has related accelerators.Mirror Accelerators are basically available from domestic cloud manufacturers:
Docker Hub Mirror Accelerator List
How do I use the Mirror Accelerator?
Docker Hub Mirror Accelerator Configuration
Linux systems can execute the following shells:
Once configured, you can check the validity of the docker info command:
What if it's Windows 10?You can configure it at the interface shown in the following figure:
Windows 10 Configuration
3. Source Change
Accelerators are cool to use, but most of the time, even with an accelerometer configured, some mirrors don't work well (possibly related to the accelerometer's international bandwidth), so you have to switch sources.Accelerators are not everything, especially when your mirror is large.Then you have to find the right source.
For example, the SDK image of.NET Core, we can use the Azure China mirror source uniformly, as shown in the table below, we can see that "mcr.microsoft.com"The corresponding agent in China is"mcr.azk8s.cn":
So we can use "mcr.azk8s.cn"instead of the official"mcr.microsoft.com"Source:
# docker pull mcr.microsoft.com/dotnet/core/sdk:2.2-stretch docker pull mcr.azk8s.cn/dotnet/core/sdk:2.2-stretch
As shown in the code above, we will change the source of Azure International to that of Azure China, and the pulling speed will be fast.Changing the source means that we also need to modify Dockerfile's commands:
#FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build #Modify to Azure China Mirror FROM mcr.azk8s.cn/dotnet/core/sdk:2.2-stretch AS build
4. Pushing self-made mirrors into domestic warehouses
What if there is no source?Can't it be cold?Do it yourself.It can be built overseas based on GitHub hosting, Azure DevOps and Docker hub, and then pushed into domestic mirror warehouses.
Relevant Mirror Label Description
Then simply replace it with your own source in the Dockerfile to enjoy a quick flight:
#See:https://github.com/xin-lai/aspnetcore-docker FROM ccr.ccs.tencentyun.com/magicodes/aspnetcore-runtime:2.2withfonts AS base
Here's a trick to share: apt packaging on Linux is often very slow and unreliable, and sometimes domestic agents are unreliable, so consider using an overseas build to mirror it.
5. Build your own near mirror warehouse
Server bandwidth is not good, local network is not good, what can I do?What else can you do? Build your own warehouse.It's recommended that you use nexus, which hosts packages like Docker, Nuget, Jar, npm, Bower, and so on. It's hardly too sharp.How to build?Yaml often takes the following exams:
apiVersion: apps/v1beta2 kind: Deployment metadata: labels: k8s-app: nexus name: nexus namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s-app: nexus strategy: type: Recreate template: metadata: labels: k8s-app: nexus spec: containers: - image: sonatype/nexus3 imagePullPolicy: IfNotPresent name: nexus resources: limits: cpu: "2" memory: 5024Mi requests: cpu: 10m memory: 256Mi volumeMounts: - mountPath: /nexus-data name: data restartPolicy: Always nodeName: k8s-node1 #Force constraints to dispatch Pod s to specified Node nodes terminationGracePeriodSeconds: 30 #The wait time (in seconds) at the end of a Pod volumes: - name: data hostPath: #Use Host Directory path: /var/nexus hostNetwork: true --- apiVersion: v1 kind: Service metadata: name: nexus namespace: default spec: ports: - name: tcp-8081-8081 nodePort: 30081 port: 8081 protocol: TCP targetPort: 8081 - name: tcp-8082-8082 nodePort: 30082 port: 8082 protocol: TCP targetPort: 8082 - name: tcp-8083-8083 nodePort: 30083 port: 8083 protocol: TCP targetPort: 8083 - name: tcp-8084-8084 nodePort: 30084 port: 8084 protocol: TCP targetPort: 8084 - name: tcp-8085-8085 nodePort: 30085 port: 8085 protocol: TCP targetPort: 8085 - name: tcp-8086-8086 nodePort: 30086 port: 8086 protocol: TCP targetPort: 8086 selector: k8s-app: nexus sessionAffinity: None type: NodePort
6. Final Solutions
Not yet. Copy it with a U disk.Don't say you know me.You don't believe you can copy it through a U drive?You can learn about the following two commands:
- docker save
- docker load