LoginSignup
0
0

【Nexus】オフラインのリポジトリサーバ構築#2 (docker-repo編)

Posted at

はじめに

前回記事で作成した環境にDockerリポジトリを作成する手順を追加する手順を共有させていただきます。


動作環境

構成図

今回の構築範囲は赤枠部分です。(pypi-repos部分は前回記事にて構築済み)

docker構築手順_nexus_repository.drawio.png

端末情報(前回同様)
※サーバ/クライアントPCにはDocker(docker-compose含む)は事前にインストールされていることを前提としています

Nexusサーバ
OS: CentOS Linux release 7.9.2009 (Core)
Docker: version 26.0.0, build 2ae903e
Docker Compose: version 1.29.1, build c34c88b2
クライアントPC(Mac)
機種: Apple M2
OS: macOS Ventura 13.3
Docker: version 24.0.6, build ed223bc
Docker Compose: version v2.23.0-desktop.1


dockerリポジトリ構築

docker用のBlob Store作成

Configulation(Repository) > Blob Stores > Create Blob Store
下記設定を行い Save を選択

Type: File
Name: pypi-repos
Path: /nexus-data/blobs/pypi-repos
Soft Quota: Disable

スクリーンショット 2024-05-26 15.08.43.png

Realmsの設定追加

Security > Realms > Docker Bearer Token Realm > Save

docker(hosted)用のRepository作成

Configulation(Repository) > Repositories > Create repository > docker(hosted)
下記設定を行い Create repository を選択

Name: docker-hosted
Online: チェック
HTTP: チェック, 8083
Blob store: pypi-repos
Strict Content Type Validation: チェック
Deployment policy: Allow redeploy
Proprietary Components: チェックなし

docker(proxy)用のRepository作成

Configulation(Repository) > Repositories > Create repository > docker(proxy)
下記設定を行い Create repository を選択

Name: docker-proxy
Online: チェック
HTTP: 8082
Allow anonymous docker pull: チェック
Remote storage: https://registry-1.docker.io
Docker Index: Use Docker Hub
Auto blocking enabled: チェック
Maximum component age: 1440
Maximum metadata age: 1440
Blob store: docker-repos
Strict Content Type Validation: チェック
Routing Rule: None
Not found cache enabled: チェック
Not found cache TTL: 1440

docker(group)用のRepository作成

Configulation(Repository) > Repositories > Create repository > docker(group)
下記設定を行い Create repository を選択

Name: docker-group
Online: チェック
Blob store: docker-repos
Strict Content Type Validation: チェック
Member repositories: docker-proxy, docker-hosted

クライアントPC(MAC)側の設定変更

Docker Desktopの設定変更

⚙ > Docker Engine を選択し、下記設定を追加し Apply & restart

  "insecure-registries": [
    "192.168.0.204:8082",
    "192.168.0.204:8083"
  ]

参考
スクリーンショット 2024-05-26 16.07.08.png

クライアントがLinuxの場合

下記設定を追加し、プロセスの再起動をする。

/etc/docker/daemon.json
{
  "insecure-registries": [
    "192.168.0.204:8082",
    "192.168.0.204:8083"
  ]
}
systemctl daemon-reload
systemctl restart docker

【オフライン】Nexusへイメージをアップロード

docker login 192.168.0.204:8083
Authenticating with existing credentials...
Login Succeeded

適当なイメージを作成

ls -l
-rw-r--r--@ 1 handson  staff  216  5 26 17:03 Dockerfile
-rw-r--r--@ 1 handson  staff   10  5 26 17:02 requirements.txt
Dockerfile
FROM python:3.6.8
USER root

RUN mkdir -p /root/src
COPY requirements.txt /root/src
WORKDIR /root/src

RUN pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN pip install -r requirements.txt
requirements.txt
requests
docker build -t 192.168.0.204:8083/docker-python368:latest .
docker images
REPOSITORY                                                TAG                                                                          IMAGE ID       CREATED          SIZE
192.168.0.204:8083/docker-python368                       latest                                                                       cc05c4c325e7   15 minutes ago   895MB

作成したイメージをアップロードしてみます。

docker push 192.168.0.204:8083/docker-python368:latest
The push refers to repository [192.168.0.204:8083/docker-python368]

GUIで反映されているかを確認
Browse > docker-hosted
スクリーンショット 2024-05-26 17.25.06.png
アップロードはOK!

【オフライン】Nexusへイメージをダウンロード

先ほどアップロードしたものをDLしてみます。

docker pull 192.168.0.204:8083/docker-python368:latest
latest: Pulling from docker-python368

docker images
REPOSITORY                                                TAG                                                                          IMAGE ID       CREATED          SIZE
192.168.0.204:8083/docker-python368                       latest                                                                       cc05c4c325e7   45 minutes ago   895MB

イメージがDLできていることを確認

【オンライン】Nexusへイメージをダウンロード

docker pull 192.168.0.204:8082/centos:latest
latest: Pulling from centos
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Image is up to date for 192.168.0.204:8082/centos:latest
192.168.0.204:8082/centos:latest

 [16:49:15] ❯ docker images
REPOSITORY                                                TAG                                                                          IMAGE ID       CREATED         SIZE
192.168.0.204:8082/centos                                 latest                                                                       e6a0117ec169   2 years ago     272MB

DL時にオンライン、オフラインの棲み分けを意識せずに使いたいのであればdocker(group)用のポート番号を設定したほうが良さそうです。

ただアップロード時はgroup用のポートにpushしたところ、下記エラーが出力されたためプロライセンスが必要なようです。

denied: Deploying to groups is a PRO-licensed feature. See https://links.sonatype.com/product-nexus-repository

参考

以下、参考にさせていただいた情報です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0