「Nexus」- 部署 3.33.0 版本,Docker Compose

  CREATED BY JENKINSBOT

问题描述

该笔记将记录:通过 Docker Compose 部署 Nexus 3.33.0 版本的方法,以及相关问题的解决办法。

解决方案

第一步、编写 Docker Compose 文件

version: "3"

services:
  package-repository:
    image: sonatype/nexus3:3.33.0
    container_name: package-repository
    restart: always 
    volumes:
      - "/srv/hdd/package-repository/nexus-data:/nexus-data"
    ports:
      - "50362:8081"

第二步、启动服务并测试

# 根据文档,nexus-data,会被 UID=200 的进程 Nexus 写入数据,所以:
mkdir -pv /srv/hdd/package-repository/nexus-data
chown 200 /srv/hdd/package-repository/nexus-data

# 启动服务
docker-compose up -d

# 查看运行日志:
docker-compose logs -f 

第三步、配置 Nginx 代理

server
{
  listen *:443;
  server_name repo.example.com;

  # allow large uploads of files
  client_max_body_size 1G;

  # optimize downloading files larger than 1G
  #proxy_max_temp_file_size 2G;

  ssl on;
  ssl_certificate example.pem;
  ssl_certificate_key example.key;

  location /
  {
    # Use IPv4 upstream address instead of DNS name to avoid attempts by nginx to use IPv6 DNS lookup
    proxy_pass http://127.0.0.1:8081/;
    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 "https";
  }
}

参考文献

sonatype/nexus3 – Docker Image | Docker Hub
Run Behind a Reverse Proxy