基础环境:centos-7, docker-ce-18.09.5
- 安装
docker-compose
1. curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2. chmod +x /usr/local/bin/docker-compose
3. docker-compose --version
// 测试安装结果
-
下载
harbor-offline-installer-v1.7.5.tg
,地址:https://github.com/goharbor/harbor/releases
备用百度网盘地址,提取码:ufbn
,此版本中的认证数据库已经换成了postgres
-
我这里使用的是离线下载的方式安装,将下载好的压缩包拷贝到虚拟机中,怎么拷贝参考这篇文章
-
将文件从物理机拷贝到虚拟机中,并复制到
/usr/local
目录下,解压缩
cp harbor-offline-installer-v1.7.5.tgz /usr/local/
cd /usr/local/
tar -zxvf harbor-offline-installer-v1.7.5.tgz
cd harbor
vim harbor.cfg
编辑配置文件并修改主机名,可以修改成虚拟机的主机名或者虚拟机的IP地址
可以修改 harbor 管理员(admin)的密码,如果不修改,默认为 Harbor12345
- 配置文件修改完成后,执行
./install.sh
命令,执行的过程中出现了一个redis
容器名称被占用的情况(由于此前我启用了一个名为 reids 的容器),删除该容器,重新执行安装
docker ps -a; // 查看所有容器
docker rm redis; // 删除 redis 容器
docker rm -f `docker ps -q`; // 删除所有正在运行中的容器
./install.sh; // 重新执行安装
安装成功后,可以看到 harbor 后台程序已经监听在了虚拟机的物理端口上,在浏览器中直接访问虚拟机IP地址:192.168.146.128
输入账号:admin
输入密码:Harbor12345
- 推送本地镜像到 harbor
1)准备工作
创建自定义账号GrandKai
,使用自定义账号登录,并创建项目auth
,进入到创建的项目中可以看到推送镜像的命令提示
1. 在项目中标记镜像:
docker tag SOURCE_IMAGE[:TAG] 192.168.146.128/auth/IMAGE[:TAG]
2. 推送镜像到当前项目:
docker push 192.168.146.128/auth/IMAGE[:TAG]
踩到的坑:在 bash 中执行 docker login 192.168.146.128
输入正确的账号密码提示如下错误,原因是客户端向服务器发起了 https
请求
编辑
/etc/docker/daemon.json
,加入 insecure-registries
配置,完整配置如下
{
"registry-mirrors": ["https://私有镜像仓库地址"],
"insecure-registries": ["192.168.146.128"]
}
重启 systemctl restart docker
,再次登录 docker login 192.168.146.128
2). 经过前面的准备工作,现在可以重新把镜像打 tag,并推送到 harbor
docker images; // 查看所有镜像
docker tag mybusybox:v3 192.168.146.128/auth/mybusybox:v3; // 将镜像重新打tag
docker push 192.168.146.128/auth/mybusybox; 将镜像推送到私有 Registry(Harbor)中
附录:daemon.json 全部配置如下:https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
{
"authorization-plugins": [],
"data-root": "",
"dns": [],
"dns-opts": [],
"dns-search": [],
"exec-opts": [],
"exec-root": "",
"experimental": false,
"features": {},
"storage-driver": "",
"storage-opts": [],
"labels": [],
"live-restore": true,
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file":"5",
"labels": "somelabel",
"env": "os,customer"
},
"mtu": 0,
"pidfile": "",
"cluster-store": "",
"cluster-store-opts": {},
"cluster-advertise": "",
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,
"default-shm-size": "64M",
"shutdown-timeout": 15,
"debug": true,
"hosts": [],
"log-level": "",
"tls": true,
"tlsverify": true,
"tlscacert": "",
"tlscert": "",
"tlskey": "",
"swarm-default-advertise-addr": "",
"api-cors-header": "",
"selinux-enabled": false,
"userns-remap": "",
"group": "",
"cgroup-parent": "",
"default-ulimits": {
"nofile": {
"Name": "nofile",
"Hard": 64000,
"Soft": 64000
}
},
"init": false,
"init-path": "/usr/libexec/docker-init",
"ipv6": false,
"iptables": false,
"ip-forward": false,
"ip-masq": false,
"userland-proxy": false,
"userland-proxy-path": "/usr/libexec/docker-proxy",
"ip": "0.0.0.0",
"bridge": "",
"bip": "",
"fixed-cidr": "",
"fixed-cidr-v6": "",
"default-gateway": "",
"default-gateway-v6": "",
"icc": false,
"raw-logs": false,
"allow-nondistributable-artifacts": [],
"registry-mirrors": [],
"seccomp-profile": "",
"insecure-registries": [],
"no-new-privileges": false,
"default-runtime": "runc",
"oom-score-adjust": -500,
"node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"],
"runtimes": {
"cc-runtime": {
"path": "/usr/bin/cc-runtime"
},
"custom": {
"path": "/usr/local/bin/my-runc-replacement",
"runtimeArgs": [
"--debug"
]
}
},
"default-address-pools":[{"base":"172.80.0.0/16","size":24},
{"base":"172.90.0.0/16","size":24}]
}
网友评论