docker harbor镜像仓库
docker harbor安装使用:
https://github.com/goharbor/harbor/releases
有离线安装和在线安装两种方式
安装:
1、下载安装包
https://github.com/goharbor/harbor/releases
在线安装包,体积小:
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.1.tgz
离线安装包,体积大:
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.1.tgz
2、修改配置文件
tar -xvf harbor-online-installer-v1.8.1.tgz
cd harbor/
vim harbor.yml
hostname: 118.xxx.xxx.xxx #主机名,可以是域名和IP
port: 80 #访问端口,做了ssl域名正式可以设置成443
harbor_admin_password: Harbor12345 #harbor页面等登录密码
database:
password: root123 #数据库密码
data_volume: /data #数据卷的路径,是本机的真实路径
3、下载docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
4、执行安装脚本
./install.sh
5、登录harbor界面
用户名:admin
密码:Harbor12345
6、启动和停止harbor
cd harbor#启动和停止harbor需要找docker-compose.yml文件,所以必须进入harbor安装目或者-f指定harbor项目的docker-compose.yml
docker-compose start/stop
7、推送镜像
docker tag SOURCE_IMAGE[:TAG] 118.xxx.xxx.xxx/myproject/IMAGE[:TAG] #打标签
docker push 118.xxx.xxx.xxx/myproject/IMAGE[:TAG] #推送
推送执行时报错:
1) The push refers to repository 118.xxx.xxx.xxx/myproject/nginx]
Get https://118.xxx.xxx.xxx/v2/: dial tcp 118.xxx.xxx.xxx:443: connect: connection refused
这是因为默认情况下访问的是443端口,需要证书认证,我们没有,需要在配置文件中添加仓库安全地址
[root@VM_0_3_centos harbor]# cat /etc/docker/daemon.json
{"registry-mirrors": ["http://f1361db2.m.daocloud.io"],
"insecure-registries": ["118.xxx.xxx.xxx"]
}
2) The push refers to repository [118.xxx.xxx.xxx/myproject/nginx]
d7acf794921f: Preparing
d9569ca04881: Preparing
cf5b3c6798f7: Preparing
denied: requested access to the resource is denied
因为我们创建的项目是私有项目,需要登录之后才能上传镜像
[root@VM_0_3_centos ~]# docker login 118.xxx.xxx.xxx
Username: admin
Password:#如果没有改动过,admin密码是Harbor12345,也可以在harbor上为项目创建一个用户
3) docker login发生错误
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
需要给docker添加dns配置
[root@VM_0_3_centos harbor]# cat /etc/docker/daemon.json
{"registry-mirrors": ["http://f1361db2.m.daocloud.io"],
"insecure-registries": ["118.xxx.xxx.xxx"],
"dns":["8.8.8.8","114.114.114.114"]
}