用Harbor搭建Docker私服

安裝docker

安裝docker-compose

安裝Harbor 1.5.2

  • 下載Harbor

https://pan.baidu.com/s/19-gntfgbQZLjoJMajMG3BQ m5cc

  • 解壓

    		tar zxf harbor-online-installer-v1.2.0.tgz  -C /usr/local/
    		cd /usr/local/harbor
    
  • 修改配置

vim harbor.cfg

hostname = abc.com

email_server = smtp.qq.com 

email_server_port = 25

email_username = [email protected]

email_password =1234567

email_from = abc <[email protected]>

email_ssl = false

harbor_admin_password = admin

db_password = admin

clair_db_password = admin

self_registration = off

project_creation_restriction = adminonly

  • 修改docker-compose.yml
 vim docker-compose.yml

registry:
    image: vmware/registry-photon:v2.6.2-v1.5.2
    container_name: registry
    restart: always
    volumes:
      - /data/registry:/storage:z
      - ./common/config/registry/:/etc/registry/:z
    networks:
      - harbor
    environment:
      - GODEBUG=netdns=cgo
    ports:
      - 5000:5000

proxy:
    image: vmware/nginx-photon:v1.5.2
    container_name: nginx
    restart: always
    volumes:
      - ./common/config/nginx:/etc/nginx:z
    networks:
      - harbor
    ports:
      - 8080:80
      - 1443:443
      - 14443:4443

  • 配置外部nginx
    server {
      server_name abc.com;

        listen 443 ssl;
        client_max_body_size 1000m;
        ssl_certificate ./cert/abc.pem;
        ssl_certificate_key ./cert/abc.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
		
		location /v2/ {
      		proxy_pass http://127.0.0.1:5000/v2/;
      		proxy_set_header Host $host;
      		proxy_set_header X-Real-IP $remote_addr;
      		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      		proxy_set_header X-Forwarded-Proto $scheme;
      		proxy_buffering off;
      		proxy_request_buffering off;
    		}
    	location / {
           proxy_pass http://127.0.0.1:8080;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
	
	
	server {
    listen 80;
    server_name abc.com;
    client_max_body_size 1000m;
    location / {
        proxy_pass              http://127.0.0.1:8080;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
     }
   }

  • Web ui

https://abc.com admin/admin

  • 外網訪問
docker login abc.com
docker tag busybox abc.com/library/busybox:admin
docker push abc.com/library/busybox:admin
docker pull abc.com/library/busybox:admin
  • 內網訪問

  • 創建/etc/docker/daemon.json

{
"registry-mirrors": [
   "https://registry.docker-cn.com"
],
"insecure-registries":["192.168.1.2:8080"]
}

  service docker restart
docker login 192.168.1.2:8080
docker tag busybox 192.168.1.2:8080/library/busybox:admin
docker push 192.168.1.2:8080/library/busybox:admin
docker pull 192.168.1.2:8080/library/busybox:admin

遇到問題

  • docker login xxx.com

Authenticating with existing credentials... Login did not succeed, error: Error response from daemon: Get https://docker.daoxuehao.com/v2/: error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor="white">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>ng

添加 80:端口

location / {
     
    proxy_pass              http://127.0.0.1:8080;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    }
  • docker push

出現 HTTP 405

https://github.com/goharbor/harbor/issues/37

location /v2/ { proxy_pass http://192.168.xxx.xxxx:5000/v2/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; proxy_request_buffering off;

} expose port 5000 in harbor Deploy docker-compose.yml

出現 HTTP 413

error parsing HTTP 413 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body bgcolor="white">\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"

server {
...
client_max_body_size 20m;
...
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章