什么是harbor仓库
Harbor是由Vmware公司开源的管理容器镜像的平台。
搭建环境
关闭防火墙和seliunx
[root@harbor ~]# systemctl stop firewalld && systemctl disable firewalld
[root@harbor ~]# setenforce 0 //临时关闭
将文件上传到root目录下
[root@harbor ~]# ls
docker-compose harbor-offline-installer-v1.7.1.tgz //上传到root目录下
安装docker并启动
[root@harbor ~]# yum -y install docker //安装docker
[root@harbor ~]# systemctl start docker //启动docker
解压harbor源码包
[root@harbor ~]# tar -xf harbor-offline-installer-v1.7.1.tgz
[root@harbor ~]# mv docker-compose /usr/local/bin/ //将docker-compose移动到指定目录
[root@harbor ~]# chmod a+x /usr/local/bin/docker-compose //赋予执行权限
导入镜像到本地镜像库
[root@docker Harbor]# cd harbor/ //进入解压目录
[root@docker harbor]# docker load -i harbor.v1.7.1.tar.gz
编辑文件
[root@harbor harbor]# vi harbor.cfg
8 hostname = 192.168.1.10 //修改为本地IP地址
69 harbor_admin_password = 000000 //为admin用户密码
执行脚本
[root@docker harbor]# ./install.sh
✔ ----Harbor has been installed and started successfully.---- //代表成功
编辑docker
[root@harbor harbor]# vi /etc/sysconfig/docker
4 OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry=192.168.1.10:80' //添加红色部分即可
5 ADD_REGISTRY='--add-registry 192.168.1.10:80'
重启docker
[root@harbor harbor]# systemctl daemon-reload //重启配置
[root@harbor harbor]# systemctl restart docker
浏览器访问:192.168.1.10
创建用户
创建项目
将创建的用户加入到项目中
登录测试
[root@harbor harbor]# docker login
Username: user
Password:
Login Succeeded
镜像加速器
[root@harbor ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://192.168.1.10.mirror.aliyuncs.com"]
}
重启docker
[root@harbor ~]# systemctl daemon-reload
[root@harbor ~]# systemctl restart docker
docker pull | 拉取镜像 |
docker tag | 打标签 |
docker push | 上传到镜像仓库 |
导入镜像仓库
从镜像仓库中拉取nginx
[root@harbor ~]# docker pull docker.io/nginx
[root@harbor ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest 605c77e624dd 3 months ago 141 MB
给nginx打标签
[root@harbor ~]# docker tag 605c77e624dd 192.168.1.10:80/aaa/nginx:latest
docker tag : 给镜像打标签
192.168.1.10:80 : harbor仓库地址
latest :版本号
上传到harbor镜像仓库
[root@harbor ~]# docker push 192.168.1.10:80/aaa/nginx:latest
在浏览器上查看