Using docker in China 2024
Docker has been blocked in China since June 6, 2024. In this post, I will cover how to use docker in China.
Installing Docker
We need to install docker by install from a package, because the docker.com
domain has been blocked in China.
You can search “install docker on {your-operating-system}” to get the information about installing docker from a package.
The steps of installing docker from a package:
- Download Docker package files.
- Upload package files to your server.
- Install the packages by command.
- Verify if the docker engine installation is successful.
Debian/Ubuntu
1. Download docker packages
- Go to
https://download.docker.com/linux/debian/dists/
orhttps://download.docker.com/linux/ubuntu/dists/
. - Select your Debian version in the list.
- Go to
pool/stable/
and select the applicable architecture (amd64
,armhf
,arm64
, ors390x
).- x86-64 (
linux/amd64
,linux/i386
) - ARM architectures (
linux/arm/v5
,linux/arm/v6
,linux/arm/v7
,linux/arm64
) - PowerPC and IBM Z (
linux/ppc64le
,linux/s390x
)
- x86-64 (
- Download the following
deb
files for the Docker Engine, CLI, containerd, and Docker Compose packages:containerd.io_<version>_<arch>.deb
docker-ce_<version>_<arch>.deb
docker-ce-cli_<version>_<arch>.deb
docker-buildx-plugin_<version>_<arch>.deb
docker-compose-plugin_<version>_<arch>.deb
2. Install docker packages
sudo dpkg -i ./containerd.io_<version>_<arch>.deb \ |
Common errors in installing docker packages
Error 1: dependency problems prevent configuration of docker-ce: docker-ce depends on iptables; however: Package iptables is not installed
.
Solutions
sudo apt update |
3. Verify
sudo service docker start |
CentOS/RHEL
1. Download docker packages
- Go to
https://download.docker.com/linux/centos/
orhttps://download.docker.com/linux/rhel/
. - Choose your version of CentOS.
- Browse to
x86_64/stable/Packages/
and download thedocker-ce_<version>_<arch>.rpm
file for the Docker version you want to install.
2. Install docker packages
sudo yum install docker-ce_<version>_<arch>.rpm |
3. Verify
sudo systemctl start docker |
Method 1: Setting Docker Mirrors
You can configure a docker mirror in /etc/docker/daemon.json
{ |
Aliyun Docker Mirror
If you have an Aliyun account. You can get a Docker mirror from 镜像加速器 of your Aliyun account.
1. Add docker mirror to /etc/docker/daemon.json
sudo mkdir -p /etc/docker |
2. Verify
$ docker info |
Server: |
# It's very slow. You may need to wait for 15 seconds. |
Using reverse proxy + Docker mirror
You can use Cloudflare workers to reverse proxy docker hub or use Nginx.
Using Cloudflare workers + Docker mirror
1. Deploy docker reverse proxy with Cloudflare workers
Go to Cloudflare -> Open Workers & Pages -> Click the “Create” button -> Click the “Create Worker” -> Click “Deploy” -> Click “Edit code” -> Paste code from CF-Workers-docker.io _worker.js
-> Click “deploy”, click “Save and deploy” -> Done.
You can also set a custom domain for your worker. Note you can only use a domain or subdomain name that is added on Cloudflare.
Click “Settings” -> “Triggers” -> “Add Custom Domain” -> Enter your custom domain, e.g. dockerhub.mydomain.com. -> Click “Add Custom Domain”
Ping the domain from your server in China to check if it’s accessible.
ping dockerhub.mydomain.com |
2. Add docker mirror to /etc/docker/daemon.json
{ |
sudo systemctl daemon-reload |
3. Verify
$ docker info |
Server: |
$ docker image ls |
Method 2: Using a network proxy client
Setting a proxy for docker
You can configure proxy behavior for the daemon in the daemon.json
file
/etc/docker/daemon.json
{ |
sudo systemctl restart docker |
Reference Configure the daemon to use a proxy
Using the global proxy mode
Turn on global mode in the proxy client.
Method 3: Save and upload Docker images
1. Pull the docker image on a computer that has access to docker
docker pull [image_name] |
2. Save one or more images to a tar archive
docker save [image_name] > [image_name].tar |
3. Load an image or repository from a tar archive
docker load < [image_name].tar |