Nexus as private docker registry
To install Nexus Repository Manager on Ubuntu, you can follow these steps:
- Prerequisites: Ensure that you have Java Development Kit (JDK) installed on your Ubuntu system. Nexus Repository Manager requires Java to run. You can install OpenJDK using the following command:
sudo apt update
sudo apt install openjdk-11-jdk
Download Nexus Repository Manager: Visit the Sonatype download page (https://www.sonatype.com/nexus/repository-oss/download) and find the latest version of Nexus Repository Manager. Copy the download link for the Linux version of the Nexus Repository Manager.
Download and extract Nexus: Open a terminal and use the
wget
command to download the Nexus Repository Manager. Replace<DOWNLOAD_LINK>
with the actual download link you copied.
wget <DOWNLOAD_LINK>
After the download is complete, extract the downloaded archive using the following command. Replace <NEXUS_VERSION>
with the actual version number.
tar -xvzf nexus-<NEXUS_VERSION>.tar.gz
- Move Nexus folder: Move the extracted Nexus folder to the desired installation location. For example, you can move it to the
/opt
directory.
sudo mv nexus-<NEXUS_VERSION> /opt/nexus
- Create Nexus user: It is recommended to run Nexus as a dedicated user. Create a new system user for Nexus using the following command:
sudo adduser --system --no-create-home --group nexus
- Configure Nexus: Change the ownership of the Nexus installation directory to the Nexus user.
sudo chown -R nexus:nexus /opt/nexus
Next, open the Nexus configuration file using a text editor.
sudo nano /opt/nexus/bin/nexus.rc
Uncomment the run_as_user
line and set it to the Nexus user.
run_as_user="nexus"
Save and close the file.
- Configure Nexus as a Service: Create a service file for Nexus to run it as a service.
sudo nano /etc/systemd/system/nexus.service
Add the following content to the file:
[Unit]
Description=Nexus Repository Manager
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
Save and close the file.
- Start Nexus: Start the Nexus service using the following commands:
sudo systemctl daemon-reload
sudo systemctl start nexus
- Access Nexus: Nexus Repository Manager should now be running. You can access it using a web browser by navigating to
http://localhost:8081
. The first time you access it, you will be prompted to set up the administrator account and configure the Nexus repository.
how to configure the docker host to have nexus as a private repository?
To configure your Docker host to use Nexus as a private repository, follow these steps:
Install Docker: Ensure that Docker is installed on your host machine. You can follow the official Docker documentation for the installation steps specific to your operating system.
Configure Docker to use Nexus as a registry: Docker needs to be configured to recognize Nexus as a private registry. Open the Docker daemon configuration file using a text editor. The location of the file depends on your operating system:
- Ubuntu:
/etc/docker/daemon.json
- Ubuntu:
If the file doesn't exist, create it.
Add the following configuration to the
daemon.json
file, replacing<NEXUS_HOST>
with the hostname or IP address of your Nexus server:{ "insecure-registries": ["<NEXUS_HOST>:8081"] }
This configuration allows Docker to communicate with Nexus over HTTP (non-secure). If you're using HTTPS, you'll need to set up TLS certificates and use the secure URL.
Save the
daemon.json
file and exit the text editor.Restart Docker: Restart the Docker daemon to apply the configuration changes. Use the appropriate command for your operating system:
Ubuntu:
sudo systemctl restart docker
Authenticate with Nexus: Before you can pull or push Docker images from/to Nexus, you need to authenticate your Docker client with Nexus. Run the following command in your terminal:
docker login -u <NEXUS_USERNAME> -p <NEXUS_PASSWORD> <NEXUS_HOST>:8081
Replace
<NEXUS_USERNAME>
and<NEXUS_PASSWORD>
with your Nexus credentials, and<NEXUS_HOST>
with the hostname or IP address of your Nexus server.This command will authenticate your Docker client with Nexus and create a login session that allows you to pull and push images.
Pull and push Docker images: You can now pull Docker images from Nexus using their full repository path. For example:
docker pull <NEXUS_HOST>:8081/<REPOSITORY>/<IMAGE>:<TAG>
Replace
<REPOSITORY>
with the name of the Nexus repository,<IMAGE>
with the name of the Docker image, and<TAG>
with the image tag.To push Docker images to Nexus, use the following command:
docker push <NEXUS_HOST>:8081/<REPOSITORY>/<IMAGE>:<TAG>
Ensure that the Docker image is properly tagged before pushing.
Subscribe to my newsletter
Read articles from Naveen Elwaka directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Naveen Elwaka
Naveen Elwaka
DevOps ๐จโ๐ป | Tech Blogger ๐จโ๐ป | Cloud Computing | Cloud Native | Open Source