sonatype-nexus3
Podman とDocker Composeでsonatype-nexus3 を使ってみる
Maven
Docker コンテナレジストリ
などの各種レポジトリを管理できる
Docker / Podman デフォルトでTLSが有効なのでHTTPSを無効にするオプションもあるっぽい
--tls-verify=false
sonatype-nexus3 Docker Hub
https://hub.docker.com/r/sonatype/nexus3/
amd64のみ
Maven リポジトリ Help
https://help.sonatype.com/en/maven-repositories.html
各種コンテナ環境での実行
Docker / Podman
Podman Pod
Docker Compose / Podman Compose
Docker/Podman build image
RaspberryPi などではimageがないのでbuild してみるがOSがamd64しかないRedHat UBI8なので不可
Docker / Podman
単純な実行
$ mkdir nexus3
$ cd nexus3
nexus-data を user 200 で用意するかvolumeを作成する
$ mkdir nexus-data
$ chown -R 200 nexus-data
使わない $ podman volume create nexus-data
$ podman run -d --name nexus3 -e INSTALL4J_VM_PARAMS="-Xms2000m -Xmx2000m" -p 8081:8081 -v ./nexus-data:/nexus-data docker.io/sonatype/nexus3:latest
パラメータは適当に指定した
Docker 等コンテナ用には別途httpd で中継が必要?
$ podman run -d --name httpd -v ./www:/usr/local/apache2/htdocs/ httpd:latest
Podman Pod
Podman で Kubernetes YAML ファイルで利用する
$ podman kube generate nexus3 -f nexu3.yaml
で出力したKubernetes YAMLファイルを利用する
RaspberryPi でVOLUME nexus-data を指定して出力した例
code:nexus3.yaml
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.3.1
# NOTE: If you generated this yaml from an unprivileged and rootless podman container on an SELinux
# enabled system, check the podman generate kube man page for steps to follow to ensure that your pod/container
# has the right permissions to access the volumes added.
---
apiVersion: v1
kind: Pod
metadata:
annotations:
io.kubernetes.cri-o.TTY/nexus3: "false"
io.podman.annotations.autoremove/nexus3: "FALSE"
io.podman.annotations.init/nexus3: "FALSE"
io.podman.annotations.privileged/nexus3: "FALSE"
io.podman.annotations.publish-all/nexus3: "FALSE"
org.opencontainers.image.base.digest/nexus3: sha256:475b55af17c769d0ecd1aaf901817e67d82d0e5b8e3b7212f941d304
org.opencontainers.image.base.name/nexus3: registry.access.redhat.com/ubi8/ubi-minimal:latest
creationTimestamp: "2024-06-29T15:24:32Z"
labels:
app: nexus3-pod
name: nexus3-pod
spec:
automountServiceAccountToken: false
containers:
- env:
- name: INSTALL4J_VM_PARAMS
value: -Xms2000m -Xmx2000m
image: docker.io/sonatype/nexus3:latest
name: nexus3
ports:
- containerPort: 8081
hostPort: 8081
securityContext:
capabilities:
drop:
- CAP_MKNOD
- CAP_NET_RAW
- CAP_AUDIT_WRITE
volumeMounts:
- mountPath: /nexus-data
name: nexus-data-pvc
enableServiceLinks: false
volumes:
- name: nexus-data-pvc
persistentVolumeClaim:
claimName: nexus-data
Pod名 nexus3-pod
コンテナ名 nexus3
YAML出力用に作ったコンテナを停止 削除 たぶん
$ podman container stop nexus3
$ podman rm nexus3
Pod登録、実行、停止
$ podman kube play nexus3.yaml
$ podman kube down nexus3.yaml
Pod一時停止と再開? (仮)
$ podman pod stop nexus3-pod
$ podman pod start nexus3-pod
Podman Quadletの例は略
Docker Compose / Podman Compose
Compose用ファイルを作成する場合 (仮
code:compose.yaml
services:
nexus:
image: docker.io/sonatype/nexus3:latest
environment:
INSTALL4J_ADD_VM_PARAMS: "-Xms2700m -Xmx2700m"
ports:
- "8081:8081"
volumes:
- nexus-data:/nexus-data
httpd:
image: docker.io/library/nginx:latest
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
- "5000:5000"
volumes:
nexus-data:
オプションなしだとメモリ不足になるので INSTALL4J_ADD_VM_PARAMS は必須かもしれない。
ディスクも充分に空いていること。
nexus初期ポートは8081
nexus-data フォルダを作成する場合はLinuxではUIDは200がいいのかも。WindowsではUIDなど特に設定しなくても使えた。
volumeにしておくと楽か
nginxはコンテナ用のリパースproxy+TLS用に設定してみたりする
Apacheのリバースはコンパイルが入りそうだったり難しそうなのでnginxがいいのか?
とりあえずリバースproxyが使える形かな?
code:nginx.conf
events {
worker_connections 10;
}
http {
server {
listen 5000;
server_name nginx;
location / {
proxy_pass http://nexus:5001/example/;
}
}
}
nexus はcompose.yaml のnexus コンテナ
podman compose up -d
適度に起動したら http://localhost:8081/ などにアクセスする。
実行後
$ podman compose ps
両方動作しているか確認する
admin のパスワードは nexus-data/admin.password の中にあり 起動後3分限定くらいで確認できる
$ podman compose exec nexus cat /nexus-data/admin.password
などで確認してみる
http://localhost:8081/ でアクセスできそうな確認
adminでログイン、アカウントを作成する
sonatype-nexus3:docker
port 5000 で使えるようにする
TLSを使う場合はnginxなどで転送が必要だったり?
とりあえずTLS無効でも使える
$ podman pull --tls-verify=false localhost:5000/
要所
admin
ユーザの作成
歯車アイコンから左のSecurity Users
Create local user
Roles で nx-admin を付けると管理者になる