部署環境:
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