1. Docker版
國外鏡像真的太難拉下來了,所以采用 docker registry 來存儲鏡像供其他節(jié)點使用,
拉取registry鏡像
sudo docker pull hub.c.163.com/library/registry:2.6.0
啟動倉庫
sudo docker run -d -p 5000:5000 -v /docker/registry:/tmp/registry hub.c.163.com/library/registry:2.6.0
將各個鏡像上傳到倉庫
sudo docker tag gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.2 202.193.74.222/k8s-dns-dnsmasq-nanny-amd64:1.14.2
sudo docker push 202.193.74.222:5000/k8s-dns-dnsmasq-nanny-amd64:1.14.2
2. Harbor版
參考文獻:
harbor搭建
harbor搭建與問題修改
Harbor也是基于registry鏡像進行搭建的,可視化界面比較友好,官網(wǎng)下載分為在線版和離線版,建議用離線版,因為在線版需要自己在國外網(wǎng)站拉取鏡像,偉大的墻的威力還是有的,離線版就簡單了,直接有版本對應好的鏡像.
- 環(huán)境與配置
安裝環(huán)境:docker1.10+,python2.7+,docker-compose1.6.0+
下載離線安裝包harbor-offline,配置harbor.cfg
修改:
hostname = n2
db_password = admin
harbor_admin_password = admin #這個是登錄密碼
啟動與訪問
通過docker-compose.yml
修改端口號
再通過./prepare
來更新配置
之后進行./install.sh
來安裝
最后通過docker-compose up -d
來啟動
啟動后通過n2:80
來訪問倉庫登錄與上傳
先進行登錄docker login n2:80
提示Login Succeeded為安裝成功
注:這里上傳需要先在web端建好項目名,比如上傳到倉庫名library
中:
sudo docker tag n2:80/library/test:v1
sudo docker push n2:80/library/test:v1
3. Errors
E1:
test@Test1:~$ sudo docker push 202.193.74.222:5000/test:latest
# ERROR
The push refers to a repository [202.193.74.222:5000/test]
Get https://202.193.74.222:5000/v1/_ping: http: server gave HTTP response to HTTPS client
解決方法1:
在/etc/docker/目錄下丁存,創(chuàng)建daemon.json
文件极舔。在文件中寫入:
{ "insecure-registries":["ip:5000"] }
解決方法2:
Centos中vim /etc/sysconfig/docker
,在文件中添加:
ADD_REGISTRY='--add-registry e2:80'
INSECURE_REGISTRY='--insecure-registry e2:80'
解決方法3:
Ubuntu中vim /etc/default/docker
,在文件中添加:
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --insecure-registry=n2:80"
重啟dockersudo systemctl restart docker
E2:
test@Test1:~$ sudo docker push n2:80/library/test:v1
85782553e37a: Waiting
745f5be9952c: Waiting
denied: requested access to the resource is denied
解決方法1:
先登錄才可以上傳,進行登錄操作
解決方法2:
用hosts名稱會異常,建議直接使用ip
E3:
ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nginx (fdeb3e538d5f8d714ea5c79a9f3f127f05f7ba5d519e09c4c30ef81f40b2fe77): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use
端口占用問題,可以通過修改端口來完成,在harbor/docker-compose.yml中修改,比如此處的80端口修改為8080操作如下:
proxy:
image: vmware/nginx:1.11.5-patched
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
ports:
- 8080:80
- 444:443
- 4443:4443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
注意這里修改了之后在上面問題E1,E2中的修改也端口
4. Shells
批量上傳腳本push_images.sh
#!/bin/bash
images=(kube-proxy-amd64:v1.6.6 kube-scheduler-amd64:v1.6.6 kube-controller-manager-amd64:v1.6.6 kube-apiserver-amd64:v1.6.6 etcd-amd64:3.0.17 pause-amd64:3.0 kubernetes-dashboard-amd64:v1.6.1 k8s-dns-sidecar-amd64:1.14.2 k8s-dns-kube-dns-amd64:1.14.2 k8s-dns-dnsmasq-nanny-amd64:1.14.2 etcd:v3.1.5)
for imageName in ${images[@]} ; do
sudo docker tag gcr.io/google_containers/$imageName e2:5000/$imageName
sudo docker push e2:5000/$imageName
sudo docker rmi e2:5000/$imageName
done
批量下載腳本pull_images.sh
#!/bin/bash## 標題 ##
images=(kube-proxy-amd64:v1.6.6 kube-scheduler-amd64:v1.6.6 kube-controller-manager-amd64:v1.6.6 kube-apiserver-amd64:v1.6.6 etcd-amd64:3.0.17 pause-amd64:3.0 kubernetes-dashboard-amd64:v1.6.1 k8s-dns-sidecar-amd64:1.14.2 k8s-dns-kube-dns-amd64:1.14.2 k8s-dns-dnsmasq-nanny-amd64:1.14.2 etcd:v3.1.5)
for imageName in ${images[@]} ; do
sudo docker pull e2:5000/$imageName
sudo docker tag e2:5000/$imageName gcr.io/google_containers/$imageName
sudo docker rmi e2:5000/$imageName
done