Docker4 dotnet uses Azure cloud storage to build high-speed Docker registry

Source: Internet
Author: User
Tags dotnet eval docker hub docker run docker registry
The most common operation of using Docker to build an application is Docker run or Docker pull, but for well-known reasons, it is not easy to get a high speed and steady access to the resources at the Docker hub at home. Although some Docker communities in the country also provide so-called accelerators, the measured results are not ideal. Today this article will introduce you how to use Azure storage to build a high-speed private Docker Hub (Registiry).

A graphic thousand words, basically see you to understand. We use the Azure Storage storage model provided by Docker Registry to connect 2 different Registry containers to the same blob storage, where one Registry container runs in the data center of Azure Hong Kong, The other one runs in my local docker-machine. When it is necessary to Docker pull, we use Hong Kong's container to operate and push into the local registry, which in fact uploads the mirror to Azure blob storage, where it can be downloaded directly from the Azure storage when pull mirroring. The speed is very fast, the key is more stable.

Building this environment is also very simple:

1. Use Docker-machine to create a container host in the Azure Data center of Hong Kong

Docker-machine Create--driver Azure--azure-subscription-id {sub-id}--azure-open-port--azure-location "EastAsia" { Machine-name}

2. Create a storage account in azure storage, get access key

If you have a Chinese version of Azure's account number, it is recommended to place the store in Beijing or Shanghai; If only the international version of the account, in Hong Kong speed is also good.

3. Start the Regsitry container in Hong Kong and local docker-machine using the same command respectively

Macos/linux Script

Docker run-d-P 5,000:5,000 \
-E registry_storage=azure \
-e registry_storage_azure_accountname= "{account Name}" \
-E registry_storage_azure_accountkey= "{access key}" \
-e registry_storage_azure_container= ' {STORAGE CONTAINER name} ' \
-E registry_storage_azure_realm= "core.chinacloudapi.cn" \
--name=registry \
--restart=always \
Registry:2
Windows Script

Docker run-d-P 5,000:5,000 ^
-E registry_storage=azure ^
-e registry_storage_azure_accountname= ' {account Name} ' ^
-E registry_storage_azure_accountkey= "{access key}" ^
-e registry_storage_azure_container= ' {STORAGE CONTAINER name} ' ^
-E registry_storage_azure_realm= "core.chinacloudapi.cn" ^
--name=registry ^
--restart=always ^
Registry:2
Note that I am using the Chinese version of the AZURE storage account, if the use of International version, please update registry_storage_azure_realm this parameter.

4. Complete mirrored pull with script

MacOS or Linux scripts pull-image.sh

 echo There are $# arguments to $: $*
 echo pulling image $ from Docker hub via Azure storage
&NBSP ; Echo Usage
 echo "-------------------------------------------"
 echo "is the offshore Docker-machine name '
 echo ' $ is ' local docker-machine name '
 echo ' $ is ' image name '
  echo "-------------------------------------------"
 
 echo "-> switch to $"
 eval $ ( Docker-machine env $
 echo "-> pulling image $
 docker pull $
 echo"-> Tag Image $ and push to local registry "
 docker tag $ localhost:5000/$3
 docker push localhost:5000/$3
 e Cho "-> Pull from registry in localhost into $"
 eval $ (docker-machine env $)
 docker Pull T:5000/$3
 docker Tag localhost:5000/$3 $
 docker rmi localhost:5000/$3
 echo "-> Done!"
Windows Script Pull-image.cmd

echo off
Echo Usage
echo "-------------------------------------------"
Echo '%1 ' is the offshore docker-machine name '
echo "%2 is the local docker-machine name"
echo "%3 is the image name"
echo "-------------------------------------------"

echo "-> switch to%1"
@FOR/F "tokens=*"%i in (' Docker-machine env%1 ') does @%i
echo "-> pulling image%3"
Docker Pull $
echo "-> tag image%3 and push to local registry"
Docker tag%3 localhost:5000/%3
Docker Push localhost:5000/%3
echo "-> Pull from registry to localhost into%2"
@FOR/F "tokens=*"%i in (' Docker-machine env%2 ') does @%i
Docker Pull Localhost:5000/%3
Docker tag localhost:5000/%3%3
Docker RMI localhost:5000/%3
echo "-> done!"
Of course, you can also run the registry container in the cloud docker-machine so you can share the registry with the team, but don't forget to join the validation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.