Docker 搭建私有仓库(registry、harbor)

2020-06-17 06:43:39易采站长站整理

为什么要弄私有仓库,大多是为了速度,我们再私有仓库中的push和pull的速度是特别快的。

利用registry快速搭建

https://hub.docker.com/_/registry/


Run a local registry: Quick Version
$ docker run -d -p 5000:5000 --restart always --name registry registry:2
Now, use it from within Docker:

$ docker pull ubuntu
$ docker tag ubuntu localhost:5000/ubuntu
$ docker push localhost:5000/ubuntu

这是官方的一个小demo。下面是我自己的实践。


# 拉取registry2.0版本
[root@FantJ ~]# docker pull registry:2
Trying to pull repository docker.io/library/registry ...
2: Pulling from docker.io/library/registry
81033e7c1d6a: Pull complete
b235084c2315: Pull complete
c692f3a6894b: Pull complete
ba2177f3a70e: Pull complete
a8d793620947: Pull complete
Digest: sha256:672d519d7fd7bbc7a448d17956ebeefe225d5eb27509d8dc5ce67ecb4a0bce54
Status: Downloaded newer image for docker.io/registry:2
# 后台启动运行
[root@FantJ ~]# docker run -d -p 5000:5000 --restart always --name registry registry:2
ce5b8bfa6d7f535906730ea3a058b00e7cfdaaa20ea0db3c49d700a4e2c8a645
[root@FantJ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/openjdk 8-jre bef23b4b9cac 2 weeks ago 443 MB
docker.io/fantj/nginx latest ae513a47849c 4 weeks ago 109 MB
docker.io/nginx latest ae513a47849c 4 weeks ago 109 MB
docker.io/registry 2 d1fd7d86a825 4 months ago 33.3 MB
# tag 镜像
[root@FantJ ~]# docker tag docker.io/nginx 127.0.0.1:5000/nginx
# 上传到私有仓库
[root@FantJ ~]# docker push 127.0.0.1:5000/nginx
The push refers to a repository [127.0.0.1:5000/nginx]7ab428981537: Pushed
82b81d779f83: Pushed
d626a8ad97a1: Pushed
latest: digest: sha256:e4f0474a75c510f40b37b6b7dc2516241ffa8bde5a442bde3d372c9519c84d90 size: 948
[root@FantJ ~]#

缺点:没有可视化管理工具,私有仓库服务宕机造成麻烦,没有用户管理机制、没有操作的记录功能。

优点:搭建操作简单

利用harbor搭建

下载地址:https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.1.tgz


wget https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.1.tgz

tar zxvf harbor-offline-installer-v1.5.1.tgz

cd harbor

修改配置harbor.cfg


hostname = fantj.top:8888

http还是https啥的自己看着改

保存退出,直接运行install.sh


cd ..
./install.sh

注意一点:harbor默认会占用80端口,所以请确保你的80端口不被占用,那怎么修改呢?