Docker 私服Harbor 相关操作

245 阅读1分钟

Harbor私服配置

  • 下载harbar https://github.com/goharbor/harbor/releases
  • 解压文件到 /alidata/docker/harbor
  • 复制配置文件 cp harbor.yml.tmp harbor.yml
  • 编辑harbor.yml文件 如下配置
#配置为IP或者域名
hostname: 192.168.159.128

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# https related config
# 我关闭了HTTPS的配置
#https:
  # https port for harbor, default is 443
#  port: 443
  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path
  • 运行install.sh脚本,即可启动了harbor就可以愉快操作啦 docker私服配置
  • 编辑vim /etc/docker/daemon.json该文件如下配置
hosts是配置打开了管理端口,便于统一管理
registry-mirrors是镜像加速仓库
insecure-registries私服地址
{
  "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"],
  "registry-mirrors": ["http://hub-mirror.c.163.com"],
  "insecure-registries":["192.168.159.128"]
}

编辑 /usr/lib/systemd/system/docker.service

#该行改成如下
ExecStart=/usr/bin/dockerd
#不要它后面的东西,因为会和daemon.json冲突
  • 然后登陆 docker login 192.168.159.128登陆成功
  • 打包镜像文件并推送到私服
#私服的镜像打包必须是以私服的地址开头的包才行如下
docker tag maven:3-jdk-8 192.168.159.128/jx-factory/jx-app-h5:2021.05.25.01
#推送镜像到私服
docker push 192.168.159.128/jx-factory/jx-app-h5:2021.05.25.01

harbor docker重启服务拉不起来问题解决

我们可以创建一个linuxservice harbor.service放置于/etc/systemd/system

[Unit]
Description=harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor

[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/docker-compose -f  /usr/local/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f  /usr/local/harbor/docker-compose.yml down

[Install]
WantedBy=multi-user.target