Deploy a Nexus 3 Npm Registry!
Part of our mission at HakunaCloud is to help companies embracing the DevOps methodology. Cloud Computing and containers simplify the adoption of the so called Full CI/CD pipeline, and Nexus 3 is useful as a private repository for npm packages.
In this post, we’re going to deploy Nexus 3 and configure an npm registry on it.
HakunaCloud is a managed container platform, that run on top of the cloud computing power provided by AWS and Google Cloud. Basically, it is docker in the clouds :). For this tutorial we’ll deploy the Nexus 3 image available on docker-hub.
A network isolate containers. Containers within the same network can connect each other using a service discovery system based on their names.
1
hakuna network create nexus3
Nexus 3 persist all its data and configuration in the /nexus-data
folder. We want that folder to be persisted - we don’t want to loose the configuration if the container is restarted!
Create a persistent volume of 20 gb with this command:
1
hakuna volume create nexus-data --size 20
Now we can run the service. We need to:
-p 80:8081
-v nexus-data:/nexus-data
--name nexus3 --network nexus3
-c 4
So that’s the run command:
1
hakuna run --name nexus3 --network nexus3 -p 80:8081 -c 4 -v nexus-data:/nexus-data sonatype/nexus3
Now we can use the Nexus 3 web ui. HakunaCloud automatically maps a FQDN fur us, that we can retrieve with hakuna ps
:
1
2
3
name image status publishs
------- -------------- ------- ----------------------------------------------------------------------------------
nexus3 sonatype/nexus3 running nexus3.eu-central-1.<ns>.v1.hakuna.cloud:80 -> 8081
Let’s open a browser to http://nexus3.eu-central-1.<ns>
.v1.hakuna.cloud
<ns>
placeholder accordingly to your namespace id, retrieved using hakuna ps
or hakuna user info
Nexus 3 creates a one-time password for the first admin login. We must retrieve it from the volume, we can access it using an additional container running an ssh server that shares the same volume:
1
hakuna run --name nexus-ssh --network nexus3 -p 22:22 -v nexus-data:/nexus-data rastasheep/ubuntu-sshd
Now, retrieve the FQDN using hakuna ps
and connect to the container using ssh to retrieve the admin’s password:
1
2
ssh root@nexus-ssh.eu-central-1.<ns>.v1.hakuna.cloud # The psw is "root"
cat /nexus-data/admin.password; echo # Execute this inside the ssh session
Click sign-in and follow the wizard to set a new password.
That’s it! We can now proceed with the npm registry configuration!
To quickly create an npm register open the administration panel on Nexus 3 and follow those steps:
npm Bearer Token Realm
from the Realms panel (npm needs it to login!)Lastly, configure npm to use the private registry with the following commands:
1
2
npm config set registry <repo-url> # Get this from the repositories list
npm login --registry=<repo-url>
If you need to manage multiple registry, check out the npm docs.
Davide Conti
Cloud Engineer @ HakunaCloud
Computer Engineer, one year experience as full stack web developer. Currently involved in cloud computing area.
"K.I.S.S."