1
2

More than 5 years have passed since last update.

Nexus Repository Manager on Docker Toolbox

Last updated at Posted at 2017-01-29

はじめに

DockerやMavenの成果物を格納するNexus Repository ManagerをDocker on Windows10 PCで構築してみました。
DockerHubからイメージをpullして立ち上げるだけのつもりだったのですが、Docker用リポジトリとして使うためには少し追加設定が必要でした。Maven用リポジトリとして使うのであれば、pullして立ち上げるだけですぐに使えます。

1. 前提

以下の環境で動作した内容を記述しています。

Windows 10 Home (64bit)
VirtualBox 5.0.26
Docker Toolbox (Docker version 1.12.6, build 78d1802)

2. 事前準備

2.1 start.shの修正

C:\Program Files\Docker Toolbox\start.shの60行目あたりのcreate部分にパラメーター「 --engine-insecure-registry mydocker:10080」を追加します。"mydocker"の部分はは2.2で修正するhostsと同期をとる必要があります。

  "${DOCKER_MACHINE}" create --engine-insecure-registry mydocker:10080 -d virtualbox $PROXY_ENV "${VM}"

2.2 hostsの修正

VirtualBoxで起動しているDocker Toolbox用Linuxのhostsに以下を追加します。
DockerHubのキャッシュとしてNexus Repository Managerを利用する際に必要です。
IPアドレスはDockerが割り当てたものに後で変更するので仮のIPで構いません。
※Maven用としてだけで使う場合は特に不要です

192.168.00.100 mydocker

image

3. Dockerイメージの取得と起動

以下のコマンドでNexus Repository ManagerのDockerイメージを取得し起動します。
今回は8081と10080ポートを利用します。用途は後ほど。

$docker run -d -p 8081:8081 -p 10080:10080 --name nexus sonatype/nexus3

image

4. Nexus Repository Managerへログイン

管理画面に管理者IDでログインします。(ID:admin, Password:admin123)
image

※IPアドレスはdocker-machine lsで調べられます。ポートは8081が割り当てられています。

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.13.0

5. DockerHub proxyの設定

設定メニューでCreate repositoryを選択します。
image

Docker (proxy)を選択します。
image

Name:DockerHub、 HTTP Connector:10080、Remote storage:https://registry-1.docker.io、 Docker Index:Use Docker Hubを入力し、画面下部までスクロールしCreate Repositoryをクリックします。
image

成功すると以下の行がリポジトリ一覧に追加されます。
image

6. Docker Proxy経由でDockerイメージを取得

以下のコマンドでalpineをpullしてみます。

$ docker pull mydocker:10080/alpine
Using default tag: latest
latest: Pulling from alpine
0a8490d0dfd3: Already exists
Digest: sha256:dfbd4a3a8ebca874ebd2474f044a0b33600d4523d03b0df76e5c5986cb02d7e8
Status: Downloaded newer image for mydocker:10080/alpine:latest

※これを実行するには、事前準備で設定したhostsのIPアドレスとNexus Repository Managerが稼働しているIPアドレスが同じである必要があります。ローカルリポジトリとしてinsecureな(HTTP)接続をするためです。

Nexus Repository ManagerのComponentsを確認してみると、ちゃんとキャッシュされています。
image

7. Maven Proxy経由でアーティファクトの取得

EclipseでMaven projectを作成し、pom.xmlを以下のように準備します。

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sample</groupId>
    <artifactId>sample</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>my-repo</id>
            <url>http://192.168.99.100:8081/repository/maven-central/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>my-repo</id>
            <url>http://192.168.99.100:8081/repository/maven-central/</url>
        </pluginRepository>
    </pluginRepositories>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>
</project>

Eclipseでmvn cleanを実行してみたところ、以下のようにproxy経由でプラグインなどが取得できました。

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 2.1 KB/sec)
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 19.0 KB/sec)
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 30.8 KB/sec)
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ sample ---
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom (4 KB at 7.4 KB/sec)
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/sonatype/spice/spice-parent/16/spice-parent-16.pom
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/sonatype/spice/spice-parent/16/spice-parent-16.pom (9 KB at 13.7 KB/sec)
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/sonatype/forge/forge-parent/5/forge-parent-5.pom
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/sonatype/forge/forge-parent/5/forge-parent-5.pom (9 KB at 13.2 KB/sec)
[INFO] Downloading: http://192.168.99.100:8081/repository/maven-central/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
[INFO] Downloaded: http://192.168.99.100:8081/repository/maven-central/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar (221 KB at 132.8 KB/sec)
[INFO] Deleting C:\dev\eclipse-ws\sample\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.543 s
[INFO] Finished at: 2017-01-29T22:46:56+09:00
[INFO] Final Memory: 6M/123M
[INFO] ------------------------------------------------------------------------

8.終わりに

わざわざDockerでNexus Repository Managerを立てる必要もないかもしれませんが、今回設定した内容でDocker imageを作成しておけば、プロジェクト毎に使い回しがしやすかったりするかもしれません。

メモ

本文とは関係ないですが、Dockerで起動しているnexusのOSにルートでログインする方法がわかったのでメモ。
login to nexus container with user id = 0 (root)
$docker exec -u 0 -it nexus bash

参考ページ

プライベートDocker-Registryにhttpで接続 [Docker-Toolbox Windows]
さわって理解するDocker入門
login to nexus container with user id = 0 (root)
sonatype/nexus3
Nexus RepositoryのDocker Registryを使ってオフラインでConcourse CIを使う

1
2
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
1
2