一般我们需要拉取镜像需要去外国的服务器上去拉取,下载就非常的慢。所以现在很多企业都会搭建一个自己的haribor仓库用来存储镜像和拉取镜像:
1.创建一个harbor文件夹:
[root@123456 ~]# mkdir -p /usr/src/harbor
[root@123456 ~]# cd /usr/src/harbor/
2.添加harbor安装包:
yum install -y docker-compose
解压安装包:并进入harbor文件下
[root@123456 harbor]# tar zxvf harbor-offline-installer-v1.9.1.tar
harbor/harbor.v1.9.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
[root@123456 harbor]# cd harbor/
3.修改配置文件:
hostname: 127.16.16.200 //设置你的主机名不能是本及IP地址
ui_url_protocol : http 添加这一项
4.执行[root@123456 harbor]# ./prepare 添加镜像
5.启动./install.sh脚本
配置http镜像仓库可信任
# vi /etc/docker/daemon.json
{"insecure-registries":[“172.16.16.200"]}//这里的地址是你搭建harbor服务的IP地址
# systemctl restart docker
6.用本地浏览器验证登录是否创建成功:
使用账号密码登录:admin 密码 Harbor12345
7.创建新项目y2001
推送镜像:
在docker镜像中把需要上传的镜像打上标签:
[root@123456 harbor]# docker tag centos7:nginx 127.16.16.200/y2001/centos7:nginx
如果使用命令行登录失败查找docker的启动文件:
[root@123456 harbor]# find / -name docker.service -type f
/usr/lib/systemd/system/docker.service
修改配置文件添加一下代码:
--insecure-registry=172.16.16.200 加上你自己设置的hostname: 127.16.16.200 //设置你的主机名
添加到:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry=172.16.16.200
重启:
[root@123456 harbor]# systemctl daemon-reload
[root@123456 harbor]# systemctl restart docker
再次登录:登录成功
上传镜像:
如果出先报错:没有权限访问镜像资源
[root@123456 harbor]# docker push 127.16.16.200/y2001/centos7:nginx
The push refers to repository [127.16.16.200/y2001/centos7]
ca7e00e4fb5e: Preparing
ac2f35f7f162: Preparing
88c1b8b8267e: Preparing
dde576857c36: Preparing
a58f61cee690: Preparing
0aeb287b1ba9: Waiting
denied: requested access to the resource is denied
解决方法:用使用命令去登录下harbor
[root@123456 harbor]# docker login 127.16.16.200
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
然后登录成功,会在/root/.docker/config.json 有文件生成,下次应该是不会denied了,如果还有denied,则去掉这个文件中的auth键值对即可
再次上传镜像:
成功:
下载镜像:
如果在其它主机需要拉取镜像:需要添加信任地址:
# vi /etc/docker/daemon.json
{"insecure-registries":[“172.16.16.200"]}
# systemctl restart docker