Docker构建Harbor私有仓库

Docker构建Harbor私有仓库

Scroll Down

安装DockerCE

安装yum工具集

yum install -y yum-utils

安装Docker源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

更新yum缓存

yum makecache fast

安装Docker

yum install -y docker-ce

启动Docker

systemctl start docker

设置Docker开机自启

systemctl enable docker

安装Docker-compose

下载docker-compose的最新版本

curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

为docker-compose添加可执行权限

chmod +x /usr/local/bin/docker-compose

验证查看docker-compose版本

docker-compose --version

安装Harbor

下载安装包

#版本根据个人选择,下载地址: https://github.com/goharbor/harbor/releases
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.0.tgz
#解压文件
[root@master harbor]# tar xvf harbor-offline-installer-v1.8.0.tgz 
harbor/harbor.v1.8.0.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml

配置harbor.yaml

#在解压后的harbor目录下修改harbor的配置
[root@master harbor]# vim harbor.yml 
#修改hostname,根据本机ip或者域名
hostname = *.*.*.*

配置 docker

docker默认使用的是https连接,harbor默认使用http连接,我们需要修改docker配置insecure registry
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry=192.168.1.1  #对应还是那个ip或域名

执行脚本

执行harbor的安装脚本

[root@master harbor]# ./install.sh 

[Step 0]: checking installation environment ...

Note: docker version: 18.09.6

Note: docker-compose version: 1.24.0

[Step 1]: loading Harbor images ...
23d9f72a5270: Loading layer [==================================================>]  33.25MB/33.25MB
1d4a1da12c02: Loading layer [==================================================>]  50.51MB/50.51MB
8eb1a006f3b0: Loading layer [==================================================>]  3.584kB/3.584kB
41b6f75847f4: Loading layer [==================================================>]  3.072kB/3.072kB
ec9bd6e4d4e8: Loading layer [==================================================>]   2.56kB/2.56kB
6d852bb664c2: Loading layer [==================================================>]  3.072kB/3.072kB
0e4ed2b5a5b8: Loading layer [==================================================>]  3.584kB/3.584kB
8dfb2b644f30: Loading layer [==================================================>]  12.29kB/12.29kB
......
Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.8.0


[Step 2]: preparing environment ...
prepare base dir is set to /home/harbor/harbor
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /secret/keys/secretkey
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secret/registry/root.crt
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir



[Step 3]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db   ... done
Creating redis       ... done
Creating registryctl ... done
Creating registry    ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating harbor-portal     ... done
Creating nginx             ... done

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://192.168.1.1. 
For more details, please visit https://github.com/goharbor/harbor .

测试

在harbor目录下执行脚本

#启动
docker-compose start
#停止
docker-compose start

打开浏览器请求:192.168.200.179 (ip或域名)
默认用户密码是:admin/Harbor12345
harbor1.png