How to Pull Docker Images in China: Effective Solutions

Due to various unknown reasons, many universities and container technology communities have shut down multiple image acceleration sites.

This has greatly affected work efficiency and development progress. In the face of this predicament, this article will introduce several effective solutions to help you smoothly pull Docker images and continue your development work.

How to Pull Docker Images in China: Effective Solutions

Today, I will introduce several methods to save your Docker.

Method 1: Some cloud image acceleration.

Method 2: Use Docker Hub and push images to your own Aliyun repository.

Method 3: Use GitHub Action to build Docker images.

Method 4: Deploy a proxy for DockerHub.

Method 5: Replace image repository prefixes.

How to Pull Docker Images in China: Effective Solutions

1. Some Cloud Image Acceleration

Some clouds include but are not limited to several major domestic clouds: Alibaba Cloud, Tencent Cloud, and Huawei Cloud. The methods used are quite similar. Here we will introduce Huawei Cloud for users.

Image Acceleration Not Available

Tencent Cloud Image Accelerator Address: https://mirror.ccs.tencentyun.com

University of Science and Technology of China: https://docker.mirrors.ustc.edu.cn

Docker Official Image (China Region) Acceleration: https://registry.docker-cn.com

Netease Cloud Image Accelerator Address: http://hub-mirror.c.163.com

Nanjing University Image Accelerator Address: https://docker.nju.edu.cn

Available Image Acceleration Sources

Alibaba Cloud Image Accelerator Address: https://XXXXX.mirror.aliyuncs.com

Huawei Cloud Image Acceleration Address: XXX.mirror.swr.myhuaweicloud.com

Daocloud Image Accelerator Address: https://docker.m.daocloud.io

Huawei Cloud Image Acceleration

Log into Huawei Cloud and search for “Container Image Service” or “SWR” to enter the console.

Click “Image Resources” —> “Image Center” —> “Image Accelerator”

How to Pull Docker Images in China: Effective Solutions

Operation Instructions

Install/Upgrade Container Engine Client

It is recommended to install version 1.11.2 or higher of the container engine client.

Configure Image Accelerator

For users with container engine client version greater than 1.11.2, log in to the virtual machine where the container engine is located as the root user.

Edit the “/etc/docker/daemon.json” file (if it does not exist, you can create it manually) and add the following content:

vi /etc/docker/daemon.json

{
    "registry-mirrors": [ "https://your-address.mirror.swr.myhuaweicloud.com" ]
}

Press "Esc", type :wq to save and exit.

Restart Container Engine

After configuration, execute systemctl restart docker to restart the container engine. If the restart fails, check other locations in the operating system (e.g., /etc/sysconfig/docker, /etc/default/docker) for the configuration of the registry-mirrors parameter, delete this parameter, and restart the container engine.

Confirm Configuration Results

Execute docker info, and when the address in the Registry Mirrors field is the address of the accelerator, it indicates that the accelerator has been configured successfully.

Alibaba Cloud Image Acceleration

https://cr.console.aliyun.com/

How to Pull Docker Images in China: Effective Solutions

Image Accelerator

Click “Image Tools” —> Image Accelerator

How to Pull Docker Images in China: Effective Solutions

2. Use Docker Hub and Push Images to Your Own Repository

I previously wrote an article: https://mp.weixin.qq.com/s/OrcBrtrZRwie3Q8eYVfl-A

Here is a diagram for explanation:

How to Pull Docker Images in China: Effective Solutions

Of course, you can also package and download it locally.

docker save busybox > busybox.tar
docker load < busybox.tar

3. Use GitHub Action to Build Docker Images

Prerequisites

1. Access to GitHub. The GitHub environment in China sometimes has connectivity issues. If you do not have a scientific environment, you can use https://github.com/521xueweihan/GitHub520 + SwitchHosts, which should still work (if you have it, just ignore this).

2. A GitHub account.

3. The free version of Action can be used for 1 hour per day and 33 hours per month (which is generally enough).

Reference blogger Wukong’s daily: Using GitHub Action to Build Docker Images http://wkdaily.cpolar.cn/archives/gc

1. You Need a GitHub Account

If you do not have an account, you need to register one.

https://github.com

2. Fork the Project DockerTarBuilder

Fork it to your own repository: https://github.com/wukongdaily/DockerTarBuilder

How to Pull Docker Images in China: Effective Solutions

3. Click Actions

Click the Actions tab and then click agree.

How to Pull Docker Images in China: Effective Solutions

Select the platform and fill in the image name.

How to Pull Docker Images in China: Effective Solutions

4. Download the Image

Click All workflows.

How to Pull Docker Images in China: Effective Solutions
How to Pull Docker Images in China: Effective Solutions

5. Decompress and Restore the Image

Upload the downloaded compressed package to the Docker host.

# Decompress
# unzip docker-images-tar.zip
Archive:  docker-images-tar.zip
  inflating: x86-64-images.tar.gz    
# Decompress again:
# tar -zxvf x86-64-images.tar.gz
# ls -lh alpine:latest-amd64.tar
-rw------- 1 mysql 127 7.8M Jul  4 16:57 alpine:latest-amd64.tar

# Import
# docker load < alpine:latest-amd64.tar

Import successful.
# docker images
REPOSITORY                                         TAG                 IMAGE ID            CREATED             SIZE
alpine                                             latest              a606584aa9aa        13 days ago         7.8 MB

4. Deploy a Proxy for DockerHub

1. Prerequisites

You need a GitHub account.

You need a Cloudflare account.

2. Access and Fork the Following Project to Your Repository

https://github.com/cmliu/CF-Workers-docker.io

3. Deploy to CF’s Pages Service

3.1 Log into Cloudflare and Click Worker and Pages

Click “Worker and Pages” and then Overview.

Click “Click pages” and then “Connect to Git”.

How to Pull Docker Images in China: Effective Solutions

3.2 Click Pages

Connect GitHub.

How to Pull Docker Images in China: Effective Solutions

After easy login.

3.3 Select the Forked Repository

How to Pull Docker Images in China: Effective Solutions

Click Save and Deploy.

Build and Deploy.

How to Pull Docker Images in China: Effective Solutions

Continue processing the project.

How to Pull Docker Images in China: Effective Solutions

4. Access and Record the Proxy Website You Just Deployed

Deployment successful, click to access the site.

How to Pull Docker Images in China: Effective Solutions

5. Custom Domain Name

This step is not mandatory.

Since the domain provided by Cloudflare is too long and hard to remember, you can use your own domain name for resolution.

The domain I configured here is dockerhub.xgss.net which is resolved from the domain.

How to Pull Docker Images in China: Effective Solutions
How to Pull Docker Images in China: Effective Solutions
# ping dockerhub.xgss.net
PING cf-workers-docker-io-1wu.pages.dev (172.66.47.123) 56(84) bytes of data.
64 bytes from 172.66.47.123 (172.66.47.123): icmp_seq=1 ttl=53 time=988 ms
64 bytes from 172.66.47.123 (172.66.47.123): icmp_seq=2 ttl=53 time=996 ms

6. Modify the Configuration File

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<- 'EOF'
{
  "registry-mirrors": ["https://docker.fxxk.dedyn.io"]  # Please replace with your own Worker custom domain
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

5. Image Repository Prefix Replacement

If you cannot directly access certain image repositories due to network restrictions, you can also try pulling images by modifying the image repository prefix. Some domestic service providers offer image repository mirroring services, allowing you to replace the original repository prefix with the corresponding domestic service provider’s prefix.

For example, replace docker.io with docker.m.daocloud.io, etc. This method may not apply to all images, but it can solve some image pulling issues.

https://github.com/DaoCloud/public-image-mirror?tab=readme-ov-file#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95

Conclusion

These are several methods to save your Docker. I hope the methods introduced in this article can help you, making your Docker journey smoother and more unobstructed.

Leave a Comment