部署环境:
CentOS Linux release 7.6.1810 (Core)
Docker version 19.03.1, build 74b1e89
docker-compose version 1.18.0, build 8dd22a9
harbor-offline-installer-v1.8.0
说明:1台服务器既做docker客户端,又做harbor仓库,ip地址:192.168.187.150
关闭防火墙:
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vi /etc/selinux/config
SELINUX=disabled
1、环境准备
yum update -y #升级操作系统软件和内核
[root@harbor ~]# more /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@harbor ~]#
2、安装docker,注意严格按照版本对应关系
yum install yum-utils.noarch
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum install docker-ce-19.03.1
[root@harbor ~]# vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry=192.168.187.150
#修改这条docker客户端访问
[root@localhost ]# systemctl daemon-reload
[root@localhost ]# systemctl start docker
[root@localhost ]# systemctl enable docker
3、安装docker-compose,注意严格按照版本对应关系
$ curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
[root@harbor ~]# chmod +x /usr/local/bin/docker-compose
[root@harbor harbor]# docker-compose -version
docker-compose version 1.18.0, build 8dd22a9
4、安装harbor
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.0.tgz
#注意下载的是离线版本,有墙。
[root@harbor ~]# tar zxvf harbor-offline-installer-v1.8.0.tgz
[root@harbor ~]# more harbor/harbor.yml
hostname: 192.168.187.150 #修改这条成本地ip
[root@localhost harbor]# ./install.sh #安装harbor,拉取服务镜像。
[Step 3]: starting Harbor ... #以下日志说明部署完成了。
Creating harbor-portal ... done
Creating nginx ... done
Creating registry ...
Creating harbor-db ...
Creating redis ...
Creating registryctl ...
Creating harbor-core ...
Creating harbor-portal ...
Creating harbor-jobservice ...
Creating nginx ...
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.187.150.
For more details, please visit https://github.com/goharbor/harbor .
5、查看启动的镜像文件
[root@localhost harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------
harbor-core /harbor/start.sh Up
harbor-db /entrypoint.sh postgres Up 5432/tcp
harbor-jobservice /harbor/start.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up 80/tcp
nginx nginx -g daemon off; Up 0.0.0.0:80->80/tcp
redis docker-entrypoint.sh redis ... Up 6379/tcp
registry /entrypoint.sh /etc/regist ... Up 5000/tcp
registryctl /harbor/start.sh Up
[root@localhost harbor]# docker-compose stop #批量关闭harbor服务,注意当前的目录,调用本地的docker-compose文件。
[root@localhost harbor]# docker-compose start
打开http://192.168.187.150,默认用户是admin、Harbor12345
6、harbor上创建用户,创建项目
(1)系统管理--用户管理--创建用户--账号:zhengg
(2)项目--新建项目--mydate:注意不要选择公开
(3)选择上面的创建的项目mydate,选择成员--添加用户--输入zhengg--角色:项目管理员
7、从公网上拉取2个镜像文件,上次到harbor仓库。
[root@localhost harbor]# docker pull nginx
[root@localhost harbor]# docker pull busybox
[root@localhost harbor]# docker tag nginx:latest 192.168.187.150/mydate/nginx:latest
[root@localhost harbor]# docker tag busybox:latest 192.168.187.150/mydate/busybox:latest
#用命令行登录docker harbor仓库
[root@localhost harbor]# docker login http://192.168.187.150
Username: zhengg
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
Login Succeeded
[root@localhost harbor]# docker push 192.168.187.150/mydate/nginx:latest
The push refers to repository [192.168.187.150/mydate/nginx]
12fdf55172df: Pushed
002a63507c1c: Pushed
1c95c77433e8: Pushed
latest: digest: sha256:099019968725f0fc12c4b69b289a347ae74cc56da0f0ef56e8eb8e0134fc7911 size: 948
[root@localhost harbor]# docker push 192.168.187.150/mydate/busybox:latest
The push refers to repository [192.168.187.150/mydate/busybox]
0d315111b484: Pushed
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: 527
8、删除本地镜像,再从harbor上拉取
[root@localhost harbor]# docker images #查看镜像信息
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.187.150/mydate/nginx latest 5a3221f0137b 5 days ago 126MB
nginx latest 5a3221f0137b 5 days ago 126MB
192.168.187.150/mydate/busybox latest db8ee88ad75f 4 weeks ago 1.22MB
busybox latest db8ee88ad75f 4 weeks ago 1.22MB
[root@localhost harbor]# docker rmi 5a3 -f #强制删除镜像
Untagged: 192.168.187.150/mydate/nginx:latest
Untagged: 192.168.187.150/mydate/nginx@sha256:099019968725f0fc12c4b69b289a347ae74cc56da0f0ef56e8eb8e0134fc7911
Untagged: nginx:latest
Untagged: nginx@sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9
Deleted: sha256:5a3221f0137beb960c34b9cf4455424b6210160fd618c5e79401a07d6e5a2ced
Deleted: sha256:9517458cc6efeca05fee894eb0dda7cda7a704a6469e4624792289c9ff4350c0
Deleted: sha256:963e4580fca3bf364728a7df40a2348939c25213d32508c53849108d05764093
Deleted: sha256:1c95c77433e8d7bf0f519c9d8c9ca967e2603f0defbf379130d9a841cca2e28e
[root@localhost harbor]# docker rmi db8 -f #强制删除镜像
Untagged: 192.168.187.150/mydate/busybox:latest
Untagged: 192.168.187.150/mydate/busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Untagged: busybox:latest
Untagged: busybox@sha256:9f1003c480699be56815db0f8146ad2e22efea85129b5b5983d0e0fb52d9ab70
Deleted: sha256:db8ee88ad75f6bdc74663f4992a185e2722fa29573abcc1a19186cc5ec09dceb
Deleted: sha256:0d315111b4847e8cd50514ca19657d1e8d827f4e128d172ce8b2f76a04f3faea
[root@localhost harbor]# docker pull 192.168.187.150/mydate/nginx #从docker harbor上拉取
Using default tag: latest
latest: Pulling from mydate/nginx
1ab2bdfe9778: Pull complete
a17e64cfe253: Pull complete
e1288088c7a8: Pull complete
Digest: sha256:099019968725f0fc12c4b69b289a347ae74cc56da0f0ef56e8eb8e0134fc7911
Status: Downloaded newer image for 192.168.187.150/mydate/nginx:latest
192.168.187.150/mydate/nginx:latest
[root@localhost harbor]# docker pull 192.168.187.150/mydate/busybox #从docker harbor上拉取
Using default tag: latest
latest: Pulling from mydate/busybox
ee153a04d683: Pull complete
Digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Status: Downloaded newer image for 192.168.187.150/mydate/busybox:latest
192.168.187.150/mydate/busybox:latest