January 11, 2021

[Note] sonatype-nexus in Docker

Docker

1. Create data folder

$ mkdir /data/docker.data/nexus && chown -R 200 /data/docker.data/nexus

2. Map the data folder and create container

$ docker run -d -p 8088:8081 --name nexus -v /data/docker.data/nexus:/nexus-data sonatype/nexus3

Wait about 3 min.  

 

Set up Nexus

1. admin password is in <data folder>/nexus/admin.password

$ more /data/docker.data/nexus/admin.password 

2. Open http://localhost:8088, ID=admin and PW=from previous step

3. Update password, create user, create repository.


Test

Set up .m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>test</id>
      <username>kkim</username>
      <password>*USER PASSOWRD SET IN NEXUS*</password>
    </server>
  </servers>
</settings>


Deploy JAR.  "repositoryId=" must match with server id from above settings.xml:

$ mvn deploy:deploy-file \
    -DgroupId=com.keithkim.test \
    -DartifactId=test-module \
    -Dversion=1.0.0 \
    -DgeneratePom=true \
    -Dpackaging=jar \
    -DrepositoryId=test \
    -Durl=http://localhost:8088/repository/keithkim/jars \
    -Dfile=/opt/jars/sqlite-jdbc-3.23.1.jar

If you get build failure like this:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.163 s
[INFO] Finished at: 2021-01-11T01:53:52-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy metadata: Could not transfer metadata com.keithkim.test:test-module/maven-metadata.xml from/to test (http://localhost:8088/repository/keithkim/jars): Transfer failed for http://localhost:8088/repository/keithkim/jars/com/keithkim/test/test-module/maven-metadata.xml 400 Bad Request -> [Help 1]

Edit this file, <DATA DIR>/etc/nexus.properties

$ vi /data/docker.data/nexus/etc/nexus.properties

Add this line:

nexus.maven.metadata.validation.enabled=false

Restart the container and try again.


No comments: