Using Docker in China: Practical Workarounds for Developers

  • Thread starter Thread starter Mike β˜•
  • Start date Start date
M

Mike β˜•

Guest
If you’re a developer working in mainland China, you’ve probably run into roadblocks when trying to use Docker. Pulling images can be slow or outright impossible due to network restrictions. Thankfully, there are several strategies to make Docker development smoother in this environment. In this post, I’ll walk you through three common approaches: Docker image mirrors, VPNs, and offloading downloads via AWS EC2.

1. Using Docker Image Mirrors​


The first and most straightforward solution is to configure Docker to use image mirrors hosted in China. Popular cloud providers like Alibaba Cloud, Huawei Cloud, and DaoCloud maintain Docker Hub mirrors. For example:


Code:
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://registry.docker-cn.com",
    "https://mirror.ccs.tencentyun.com"
  ]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

With this setup, docker pull requests will use mirrors instead of Docker Hub directly, drastically improving speed and reliability. That said, mirrors in China can sometimes be unreliable or change without notice, so you may need to periodically update your configuration.

Tip for travelers: If you are planning to travel to China, it’s best to prepare ahead of time by saving the Docker images you’ll need locally. That way, you can load them once you arrive without depending on Chinese mirrorsβ€”or even set up your own local mirror archive for convenience.

2. Using a VPN​


If mirrors don’t work for the images you need, another option is a reliable VPN. By tunneling your traffic outside of China, you can access Docker Hub without restrictions. The main downsides are:

  • VPNs can be unstable, especially for large image downloads.
  • Some organizations or ISPs may block certain VPNs.

A popular option is Trojan-Qt5, a client application that uses the Trojan proxy protocol. Trojan is specifically designed to bypass China’s β€œGreat Firewall” by mimicking secure HTTPS traffic, making it more reliable for pulling large Docker images than traditional VPNs.

For occasional image pulls, a VPN or Trojan-based proxy can be enough to bridge the gap.

3. AWS EC2 as a Docker Proxy​


A more robust solution is to use AWS EC2 (or another cloud provider outside China) as a proxy for downloading images. Here’s how it works:

  1. Spin up an EC2 instance in a nearby region like Singapore or Tokyo.
  2. Install Docker on that EC2 instance.
  3. Pull the Docker image you need from Docker Hub:

Code:
   docker pull ubuntu:latest
  1. Save the image into a tarball:

Code:
   docker save ubuntu:latest -o ubuntu.tar
  1. Upload the tarball to a file hosting service with fast downloads in China (e.g., AWS S3 with CloudFront, Google Drive, or a free file-sharing service).
  2. Download the tarball to your machine in China.
  3. Load the image locally:

Code:
   docker load -i ubuntu.tar

This method ensures you can grab any image, even if it’s not available via Chinese mirrors.

Wrapping Up​


Working with Docker in China requires some extra effort, but it’s far from impossible. Here’s a quick summary:

  • Save images before traveling: If you know you’ll be in China, prepare by saving images locally or setting up your own mirror.
  • Try mirrors first: They’re the simplest, but keep in mind they may change or become unreliable.
  • Use a VPN or Trojan-Qt5 if needed: Works in many cases, with Trojan-Qt5 offering a strong way to bypass restrictions.
  • Leverage AWS EC2 as a proxy: The most flexible solution for any image.

With these strategies in your toolbox, you’ll spend less time fighting with Docker and more time building what matters.

Have you tried other creative workarounds for Docker in China? Share your approach in the commentsβ€”I’d love to hear how you’ve solved this problem!

Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top