K8s中,没有管理镜像的服务,我们需要自己搭建一个镜像服务器,现在有docker registry 和Harbor ,主要是Harbor具有管理镜像的web界面和权限的管理,而比较老的docker registry ,没有这种服务,所以采用harbor.
官网文档
https://vmware.github.io/harbor/cn/
安装文件
https://github.com/vmware/harbor/releases/#download
#这个是2018年6月5号的最新版本
wget https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.1.tgz
#个人地址
链接:https://pan.baidu.com/s/1yxAfllt5qY0noFSmsy5qkQ
安装准备
yum install docker -y
systemctl start docker
#安装 pip
yum install python-pip -y
#更新pip
pip install --upgrade pip
#安装docker-compose
pip install docker-compose
#更新docker-compose
pip install --upgrade docker-compose
#查看版本
docker-compose -v
开始安装
#配置harbor.cfg 设定域名
vim harbor.cfg
#安装服务
./install.sh
#后面的命令,不是必须执行的,我们执行这个命令,必须实在harbor的解压目录下
#启动服务
docker-compose up
#后台启动服务
docker-compose up -d
#停止服务
docker-compose down
修改hostname
管理员的密码,默认是Harbor12345 ,我们可以手动修改。
安装服务,然后就安装上了
访问web
添加镜像
添加镜像的时候,一定要确定第一个(确定域名是正确的),和第二个参数是正确的(确保创建了这个项目),这样才能正确的添加到服务器上
#先登陆
docker login harbor.yellowcong.com
#给我们想要上传的镜像打tag
#第一个 harbor.yellowcong.com 这个是镜像仓库名称
#第二个 library 创建的项目名称
#第三个 java 这个可以随便起,
docker tag 4aefdb29fd43 harbor.yellowcong.com/library/java
#上传镜像到 library
docker push harbor.yellowcong.com/library/java
重新大好的tag
从web上,可以看到上传的镜像了
新建项目
新建一个springboot的项目
docker tag 4aefdb29fd43 harbor.yellowcong.com/springboot/java
#推送到服务器上
docker push harbor.yellowcong.com/springboot/java
登陆后的镜像
常见错误
1ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nginx
ERROR: for proxy Cannot start service proxy: driver failed programming external connectivity on endpoint nginx (60a8cd5be185ba394514bdbde4c46fb82e6fd0187026706c709d7b09d1ba3a5c): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use
ERROR: Encountered errors while bringing up the project.
导致这个问题的原因,是由于默认监听的是80端口,我们只需要把80端口给habor让出来即可。
2 ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
ERROR: for harbor-db UnixHTTPConnectionPool(host=‘localhost’, port=None): Read timed out. (read timeout=70)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60)
3 denied: requested access to the resource is denied
导致这个问题的原因,是由于push的名称有问题,第一个名称为 仓库的域名,第二个为项目的名称,第三个是版本信息了
正确的推送镜像
4 getsockopt: connection refused
这个问题是下载是https导致的 ,这个需要访问 镜像仓库的443的https的接口。
Create or modify /etc/docker/daemon.json
{ "insecure-registries":["myregistry.example.com:5000"] }
Restart docker daemon
systemctl restart docker.service
参考文章
https://blog.csdn.net/jessise_zhan/article/details/80129886
https://www.kubernetes.org.cn/1485.html
https://www.cnblogs.com/biglittleant/p/7283738.html