【Docker】简易版harbor部署

依赖于docker-compose

下载

curl -L “https://github.com/docker/compose/releases/download/2.22.0/docker-compose- ( u n a m e − s ) − (uname -s)- (unames)(uname -m)” -o/usr/local/bin/docker-compose

添加执行权限

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

测试

docker-compose --version

安装harbor

下载

wget https://github.com/goharbor/harbor/releases/download/v2.8.4/harbor-offline-installer-v2.8.4.tgz

解压

tar -zxvf harbor-offline-installer-v2.8.4.tgz

修改配置文件

cd harbor & cp harbor.yml.tmpl harbor.yml & vi harbor.yml

部署

./install.sh

配置开机自启动

docker-compose -f docker-compose.yml up -d

登录验证

使用harbor

登录

docker login 192.168.19.102:8000

打标签

docker tag {image name}:{tag} {harbor ip}:{port}/{harbor project}/{image name}:{tag}
# eg
docker tag apache-doris:1.2.6-be 192.168.19.102:8000/doris/apache-doris:1.2.6-be


docker commit container-name {harbor ip}:{port}/{harbor project}/{image name}:{tag}

上传

docker push {harbor ip}:{port}/{harbor project}/{image name}:{tag}
# eg
docker push 192.168.19.102:8000/doris/apache-doris:1.2.6-be

下载

docker pull {harbor ip}:{port}/{harbor project}/{image name}:{tag}
# eg
docker pull 192.168.19.102:8000/doris/apache-doris:1.2.6-be

常见问题

  • docker login问题:Error response from daemon: Get https://: http: server gave HTTP response to HTTPS client

    # 原因:服务器通过docker login命令登录报错
    
    # 解决方法
    vi /etc/docker/daemon.json
    {
      "insecure-registries": ["192.168.19.102:8000"]
    }
    
    systemctl daemon-reload
    systemctl restart docker
    
    [root@iZuf61frmjzzdoqitgbd9hZ harbor]# docker login 192.168.19.102:8000
    Username: admin
    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
    
  • k8s无法下载镜像 unauthorized: unauthorized to access repository

    # 创建secret
    kubectl create secret docker-registry harbor-login-registry --docker-email=dd@example --docker-username=admin --docker-password=admin --docker-server=192.168.19.102:8000	
    
    # k8s yaml增加配置
    imagePullSecrets: # 使用密码登录
      - name: harbor-login-registry