In China, to pull an image from the official DockerHub takes a lot of time. So it will be very helpful.
Reference:
https://docs.docker.com/registry/
Pull the registry
image
docker pull registry
Start your registry
docker run -d -p 5000:5000 --restart=always --name registry registry
Now the registry is up and running. But you have to do a bit more configuration to get it working. Because by default, Docker doesn’t allow insecure registry. If you try to push an image to your private registry now, it will prompt you with error messages. So to walk around the issue:
Tell Docker daemon to accept insecure registry, by adding --insecure-registry
to the config file /etc/sysconfig/docker
on CentOS
OPTIONS='--selinux-enabled --insecure-registry <YOUR_IP_ADDRESS>:5000'
Reload and restart docker
systemctl daemon-reload
systemctl restart docker
Now, you can get any image from the hub and tag it to point to your registry
docker pull ubuntu && docker tag ubuntu <YOUR_IP_ADDRESS>:5000/ubuntu
… then push it to your registry:
docker push <YOUR_IP_ADDRESS>:5000/ubuntu
… then pull it back from your registry:
docker pull <YOUR_IP_ADDRESS>:5000/ubuntu
Update1:
If your server is behind proxy, you may need to tell docker to use the proxy when pulling images from official registry and to ignore the proxy when pulling or pushing using your private registry.
First, create a systemd drop-in directory for the docker service:
mkdir /etc/systemd/system/docker.service.d
Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf
that adds the HTTP_PROXY environment variable:
[Service]
Environment="HTTP_PROXY=http://<YOUR_PROXY>:80/" "NO_PROXY=localhost,127.0.0.1,<YOUR_IP_ADDRESS>"