Back to projects
Build and Push Docker image to Docker repository on Nexus
- Create Docker hosted repository on Nexus - Create Docker repository role on Nexus - Configure Nexus, DigitalOcean Droplet and Docker to be able to push to Docker repository - Build and Push Docker image to Docker repository on Nexus
(same firewall/ssh key steps)
For our droplet to be able to handle Nexus effectively, we need to allocate atleast 8GB of ram/4 CPUS... for that we choose the below plan:
![[Pasted image 20250627114346.png]]
![[Pasted image 20250627115655.png]]
We do this to follow the **Principle of Least Privilege (PoLP)** principle, where we create a separate user for each service (Nexus in this case), which enables us to limit the damage if the service gets compromised.
![[Pasted image 20250627120603.png]]
![[Pasted image 20250627122512.png]]
If Nexus gets hacked, this step will prevent the hacker from accessing anything outside `/opt/nexus` and `/opt/sonatype-work` (Can't touch system files, kill other system services etc...)
![[Pasted image 20250627124336.png]]
![[Pasted image 20250627124323.png]]
![[Pasted image 20250627133841.png]]
verify it's running:
![[Pasted image 20250627133902.png]]
(it's listening on port 8081)
Navigate to Networking => Firewall tab and modify your firewall that is connected to your droplet (or create a new firewall), and a new inbound rule for TCP, port 8081 and allow all IPV4/IPV6 connections.
Hit save, make sure that the firewall is applied to the droplet and exit
![[Pasted image 20250627134354.png]]
## Step 10: Access the nexus dashboard page through the web
we access http://159.65.125.91:8081/ (replace the IP address with your droplet IP address), we see this:
![[Pasted image 20250627134743.png]]
we then login with the admin account
We navigate to settings => repositories => Create Repository and we choose "docker (hosted)"
![[Pasted image 20250705155244.png]]
We name it "docker-hosted" and leave everything else as it and click "Create repository" in the bottom of the page
![[Pasted image 20250705155507.png]]
We navigate to Settings => Security => Roles => Create Role and fill the details for the privileges we select `nx-repository-view-docker-docker-hosted-*` , leave everything else as it and click "Save"
![[Pasted image 20250705173923.png]]
We navigate to Settings => Security => Users => Create User then fill the basic info and assign this user the `nx-docker` role we created in Step 2
![[Pasted image 20250705174118.png]]
Edit the `docker-hosted` repository by enabling HTTP connector and setting the port to 8083
This will allow us to push our docker images to our docker repository hosted in our Nexus server through port 8083.
![[Pasted image 20250705174727.png]]
We navigate to Networking => Firewalls and edit our firewall that is applied to our droplet by adding an inbound rule that allows connections through port 8083
![[Pasted image 20250705175145.png]]
We navigate to Settings => Security => Realms and activate `Docker Bearer Token` and click save. This will allow Nexus to issue authentication tokens compatible with the Docker client, enabling secure push and pull operations from Docker CLI
![[Pasted image 20250705180137.png]]
Since our nexus server is using HTTP instead of HTTPS, we need to configure docker so that it allows us to push/pull to that endpoint by adding the line: `"insecure-registries": ["165.22.73.173:8083"]`
Then click Apply and Restart
![[Pasted image 20250705180813.png]]
We run the command `docker login 165.22.73.173:8083`, which will allow Docker to authenticate with the Nexus Docker registry using the provided credentials and obtain a bearer token — enabling secure access for pushing and pulling images to and from the private registry, even when accessed over HTTP (thanks to the configured `insecure-registries`).
![[Pasted image 20250705181417.png]]
We have this simple node-js app running on port 3000 (locally) that we wanna push to our nexus docker repo
![[Pasted image 20250705182916.png]]
We build a docker image out of our project and name it `my-app:1.0` for now
![[Pasted image 20250705183024.png]]
Then we re-tag it using the command:
`docker tag my-app:1.0 165.22.73.173:8083/my-app:1.0`
Where: - 165.22.73.173 is the ip address of our Digital Ocean droplet - 8083 is the port that accepts http push/pull requests as we configured it previously - my-app is the name of the docker image we created on the previous step - 1.0 is the version of our app
![[Pasted image 20250705183452.png]]
We push our created tagged image using the command :
`docker push 165.22.73.173:8083/my-app:1.0`
![[Pasted image 20250705183623.png]]
When we navigate to the docker repository inside Nexus, we can view pushed docker image there:
![[Pasted image 20250705183827.png]]