:::info 视频演示 https://www.bilibili.com/video/BV1gv411w7SU/ :::

准备工作

申请域名 SSL

上传至 $PWD/nexus3/certs

本地域名解析

windows C:\Windows\System32\drivers\etc\hosts linux /etc/hosts

创建数据路径并设置权限

  1. mkdir -p $PWD/nexus3/data && chmod 777 $PWD/nexus3/data && cd $PWD/nexus3

部署

docker-compose.yml

  1. version: "3.7"
  2. services:
  3. nexus3:
  4. image: sonatype/nexus3:3.33.1
  5. container_name: nexus3
  6. restart: always
  7. privileged: true
  8. environment:
  9. - TZ=Asia/Shanghai
  10. volumes:
  11. - $PWD/data:/nexus-data
  12. nginx:
  13. image: nginx:1.21.1-alpine
  14. container_name: nginx
  15. restart: always
  16. environment:
  17. - TZ=Asia/Shanghai
  18. ports:
  19. - "80:80"
  20. - "443:443"
  21. volumes:
  22. - $PWD/nginx.conf:/etc/nginx/nginx.conf:ro # nginx配置
  23. - $PWD/certs:/certs # SSL证书
  24. - $PWD/log:/var/log/nginx
  25. depends_on:
  26. - nexus3
  27. logging:
  28. driver: "json-file"
  29. options:
  30. max-size: "5g" # 限制日志大小

nginx.conf

  1. worker_processes 4;
  2. worker_rlimit_nofile 40000;
  3. events {
  4. worker_connections 8192;
  5. }
  6. http {
  7. upstream nexus3_http {
  8. server nexus3:8081;
  9. }
  10. server {
  11. listen 80;
  12. server_name hub.haifengat.com; # 域名替换
  13. location / {
  14. proxy_pass http://nexus3_http;
  15. proxy_set_header Host $host;
  16. proxy_set_header X-Real-IP $remote_addr;
  17. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  18. proxy_set_header X-Forwarded-Proto $scheme;
  19. proxy_set_header Upgrade $http_upgrade;
  20. proxy_set_header Connection "Upgrade";
  21. }
  22. }
  23. upstream nexus3_ssl {
  24. server nexus3:8082;
  25. }
  26. server {
  27. listen 443 ssl;
  28. server_name hub.haifengat.com; # 域名替换
  29. # SSL
  30. ssl_certificate /certs/20220824_hub.haifengat.com.pem;
  31. ssl_certificate_key /certs/20220824_hub.haifengat.com.key;
  32. client_max_body_size 5000m; # 上传大文件
  33. location / {
  34. proxy_pass http://nexus3_ssl;
  35. proxy_set_header Host $host;
  36. proxy_set_header X-Real-IP $remote_addr;
  37. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  38. proxy_set_header X-Forwarded-Proto $scheme;
  39. proxy_set_header Upgrade $http_upgrade;
  40. proxy_set_header Connection "Upgrade";
  41. }
  42. }
  43. }

运行

  1. docker-compose up -d

文件列表

image.png

配置 nexus3

登录

http://hub.haifengat.com

配置

  • 修改admin密码为Harbor12345
  • 允许匿名读取数据
  • 创建 docker(hosted) 仓库
  • 设置http 8082端口
  • Allow anonymous docker pull (不要勾选)

    daemon.json

    1. # 增加信任
    2. "insecure-registries": ["https://hub.haifengat.com"]

    QA

    502 Bad Gateway

    配置 nexus3 时使用 http 而非 https

no basic auth credentials

需要先 docker login 登录

401 Unauthorized

docker login -u admin -p Harbor12345 hub.haifengat.com 登录时报错

image.png

不允许匿名

image.png

404 response body: invalid character ‘<’ …

解决

  1. docker login -u admin -p Harbor12345 hub.haifengat.com