最后更新时间:2018年12月27日


Docker使用代理上网去 pull 各类 images,需要做如下配置:

创建目录: /etc/systemd/system/docker.service.d

写入配置:http-proxy.conf

[root@localhost docker.service.d]# cat http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.6.130:8000/"
Environment="HTTPS_PROXY=http://192.168.6.130:8000/"
Environment="NO_PROXY=localhost,127.0.0.1,192.168.6.155,192.168.6.156,192.168.6.157,registry"

注意:NO_PROXY需要单个IP写,如果命令中涉及主机名的需要在这写主机名,如下面 docker push 到 registry。

搭建私有库

创建本地仓库容器:
docker pull registry
docker run -d -p 5000:5000 --name=registry --restart=always --privileged=true -v /data/registrydata:/tmp/registry registry

修改配置增加 insecure-registries:

[root@localhost ~]# cat /etc/docker/daemon.json

{
   "insecure-registries": [
         "registry:5000"
     ]
}

重启服务

systemctl daemon-reload

systemctl restart docker

添加新tag,测试推送
docker tag docker.io/googlecontainer/kubernetes-dashboard-amd64 registry:5000/kubernetes-dashboard-amd64:v1.5.1
docker push registry:5000/kubernetes-dashboard-amd64

[root@localhost ~]# docker push registry:5000/kubernetes-dashboard-amd64    
The push refers to a repository [registry:5000/kubernetes-dashboard-amd64]
25820b2590cc: Pushed
v1.5.1: digest: sha256:b9061ebcf970a0782babd20e6a5570c5cf81dc421d81643657a84210f80092fb size: 529

验证

[root@localhost ~]# curl -XGET http://registry:5000/v2/_catalog
{"repositories":["kubernetes-dashboard-amd64","pod-infrastructure"]}