[Docker] How to setup private registry

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>"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值