{"id":5075,"date":"2024-09-27T04:57:26","date_gmt":"2024-09-27T04:57:26","guid":{"rendered":"https:\/\/www.liainfraservices.com\/blog\/?p=5075"},"modified":"2025-02-25T07:27:56","modified_gmt":"2025-02-25T07:27:56","slug":"how-to-create-private-repositories-in-nexus","status":"publish","type":"post","link":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/","title":{"rendered":"How to create Private Repositories in Nexus?"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 7<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span><div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 3,450<\/span><\/div>\n<p class=\"wp-block-paragraph\">In the world of DevOps, storing and managing artifacts\u2014whether they\u2019re Docker images, WAR files, or other build outputs\u2014is crucial for a smooth Continuous Integration\/Continuous Deployment (CI\/CD) pipeline. Public repositories like DockerHub or npm are great, but they don&#8217;t provide the control many organizations need. That&#8217;s where private repositories like Nexus Repository Manager come into play. In this guide on <strong>how to create private repositories in Nexus<\/strong>, and to create a private docker registry in nexus we\u2019ll explore how to set up Nexus, the different types of repositories it supports, and why it&#8217;s a must-have for managing artifacts in a secure, organized, and scalable way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is an Artifacts?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Artifacts are the output of any software build process, for example .exe file is an artifacts<\/li>\n\n\n\n<li>When we create a docker image using docker build command, it creates a docker image as an output and this is an artifacts<\/li>\n\n\n\n<li>Basically, Artifacts can be anything, including Docker images, text files, or Helm charts.<\/li>\n\n\n\n<li>There are other examples as well, for JAVA based software the artifacts are WAR files, reports, log files, zip, tar etc<\/li>\n\n\n\n<li>So, to store all these artifacts we need a repository and one of those repositories is Nexus<\/li>\n\n\n\n<li>Nexus is one of the products of a company called Sonatype<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a list of programming languages and their tools needed to build<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"212\" src=\"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/1724759676863-1024x212.png\" alt=\"This is a list of programing language and the tools they use to manage the software and their public repositories from where they download the packages\" class=\"wp-image-5077\" style=\"width:1137px;height:auto\" srcset=\"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/1724759676863-1024x212.png 1024w, https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/1724759676863-300x62.png 300w, https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/1724759676863-768x159.png 768w, https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/1724759676863.png 1422w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is a list of programing language and the tools they use to manage the software and their public repositories from where they download the packages<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why do we need a repository, we can directly push the artifacts to our deployment server?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ok, so, we need to understand, deployment is a different process and that comes under CD<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&amp; Creating the artifacts is coming under CI<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During CI, the pipeline creates the artifacts and stores in some remote repo like Nexus<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&amp; during the CD process, the artifacts gets pulled from repo and get applied into the Deployment<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Everytime we push the artifacts into Nexus, it gets versioned and its easier to rollback to older version, rather rebuilding a new artifacts using old source commitments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we use any public repositories like Dockerhub, npm, apt-get, yum we dont have any control on the access, but the Private repo like Nexus has granular control on user level and on policy level as well<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, we have to configure the Nexus to be a single point of truth for all the repositories an organisation needs to protect their IP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To have controll on the Private repository like Nexus, we need something called Repository Manager which ensures<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Configure users, provide RBAC to controll the access control<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; It helps to store or retrieve any build artifacts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; It helps to create different types of Repositories (`3 types` &#8211; Proxy Repo, Hosted Repi, Group Repo )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Repository Manager helps proxy any remote repositories &amp; caches its content locally for further use by the internal orgs<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Maintains a repo for its own internal artifacts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are the different types of Repositories Nexus has?<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"570\" height=\"286\" src=\"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Nexus_Repositories.png\" alt=\"\" class=\"wp-image-5078\" srcset=\"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Nexus_Repositories.png 570w, https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Nexus_Repositories-300x151.png 300w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Nexus Repository Manager has three types of repositories<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211; Proxy repositories: Acts as a cache for public repositories like Dockerhub for Docker images.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>The public repo url https:\/\/hub.docker.com\/ should be whitelisted in the proxy server<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1195\">&#8211; Hosted repositories: Store build artifacts on Nexus, accessible only to the user with SSO, or Ldap or users from orgs. Not from the outside world.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember1196\">&#8211; Group repositories: Combines multiple hosted and proxy repositories into a single logical group, providing a unified view for clients.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Install Nexus on Ubuntu server<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install Java first (Ensure the right jdk version)<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\nsudo apt install openjdk-17-jre-headless\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>create a nexus user<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\nsudo adduser --system --no-create-home --disabled-login --gecos &quot;&quot; nexus\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>Download the installation files<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\ncd \/opt\n\nsudo wget https:\/\/download.sonatype.com\/nexus\/3\/latest-unix.tar.gz\n\nsudo tar -zxvf latest-unix.tar.gz\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"ember7239\">Install Nexus on Ubuntu server<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install Java first (Ensure the right jdk version)<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install openjdk-17-jre-headless<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>create a nexus user<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo adduser --system --no-create-home --disabled-login --gecos \"\" nexus<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download the installation files<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/opt\n\nsudo wget https:\/\/download.sonatype.com\/nexus\/3\/latest-unix.tar.gz\n\nsudo tar -zxvf latest-unix.tar.gz<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Change the user ownership of nexus<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/opt\n\nsudo mv nexus-3.* nexus\n\nsudo mkdir -p \/opt\/sonatype-work\n\nsudo chown -R nexus:nexus \/opt\/sonatype-work\n\nsudo chown -R nexus:nexus \/opt\/nexus \/opt\/sonatype-work<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the nexus user to run the nexus<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vim  \/opt\/nexus\/bin\/nexus.rc\n\nAdd the following line:\n\nrun_as_user=\"nexus\" <\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start the Nexus<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo -u nexus \/opt\/nexus\/bin\/nexus start<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Verify if the nexus is running<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">ps aux | grep nexus<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7248\"><strong>Configuration of the Nexus Server<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7249\">From the browser type this<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Nexus_ip_address:8081 (Or DNS name, if the DNS entries are done with the org DNS)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7250\">User name : admin | Password &#8211; Need to ssh to the nexus server and find the password based on the location that the UI instructs.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>setup a new password<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember7253\">What we can do with Nexus Repository and its facts?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Creation: Create hosted, proxy, or group repositories.<\/li>\n\n\n\n<li>Configuration: Set policies for retention, cleanup, and indexing.<\/li>\n\n\n\n<li>Artifact Formats:<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7255\">&#8211; Support: Nexus supports various artifact formats, including Maven, npm, Docker, and more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7256\">&#8211; Configuration: Configure specific settings for each format.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Security:<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7258\">&#8211; Authentication: Configure authentication mechanisms like LDAP, Active Directory, or internal users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7259\">&#8211; Authorization: Define roles and permissions for different users.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7260\">&#8211; Encryption: Protect sensitive data like passwords and credentials.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7261\">&#8211; There are two types of user we can create on Nexus<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7262\">&#8211; 1. Anonymous user &#8211; They get only access to the repo contents (GET &#8211; Read only ), but they are restricted on other actions like create, delete, upload etc<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7263\">&#8211; 2. Regular user &#8211; Each user can have different Roles with different privileges<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7264\">&#8211; There are some default privilege available for Nexus see the lists here <a href=\"https:\/\/help.sonatype.com\/en\/privileges.html\">https:\/\/help.sonatype.com\/en\/privileges.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7265\">&#8211; generally Jenkins integrations are pretty common, where we want the Jenkins to upload the artifacts into Nexus, so we have to create a user Jenkins and assign a role with privilege as create &amp; read &#8211; but not delete<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember7266\">Is there any best practices to manage and maintain a private repository?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7267\">&#8211; Regular Cleanup: Regularly clean up old or unused artifacts to optimize storage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7268\">&#8211; Security Audits: Conduct regular security audits to identify and address vulnerabilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7269\">&#8211; Performance Optimization: Monitor performance and optimize settings as needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7270\">&#8211; Version Control: Use version control for Nexus configuration to track changes and facilitate rollback.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7271\">&#8211; Backup and Recovery: Implement a robust backup and recovery plan to protect your repository data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7272\">&#8211; Promotion of repository<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7273\">&#8211; When we build an artifacts, that build does not get used in the production deployment<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7274\">&#8211; First it stores itself into staging repository<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7275\">&#8211; The tests are performed on the staging repo and if it passes all the tests, vulnerability tests,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7276\">&#8211; The artifacts gets promoted into production repository to be used by prod deployment<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember7278\">Let`s see an example of creating a private Repo for Docker images.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7280\">Create a Private Nexus Repo for Docker images<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to Nexus, click Create Repo<\/li>\n\n\n\n<li>Select Docker Hosted<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D4D12AQFkXoRReO4B5A\/article-inline_image-shrink_1500_2232\/article-inline_image-shrink_1500_2232\/0\/1724831965910?e=1732752000&amp;v=beta&amp;t=tzH6nqDUGUL_lzK3_pktlpWZNaIxRx4CQB-T4KBMtxg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">&#8211; Create a Docker hosted repo on Nexus<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D4D12AQHC7J7I9ixThQ\/article-inline_image-shrink_1000_1488\/article-inline_image-shrink_1000_1488\/0\/1724832014255?e=1732752000&amp;v=beta&amp;t=25TIJ1C2ARnw8xx5hAHWvcMX0GIyvzrStRX3gAGPJmo\" alt=\"\"\/><figcaption class=\"wp-element-caption\"><br>Repository settings for Hosted Repo<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update the Realm as active Docker Bearer Token Realm<\/li>\n\n\n\n<li>This is necessary for authentication when using Docker with Nexus.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D4D12AQFfaxLq3FE4Sg\/article-inline_image-shrink_1000_1488\/article-inline_image-shrink_1000_1488\/0\/1724832049030?e=1732752000&amp;v=beta&amp;t=glMv9Mq5cH8rDxBDS--OViuW5oJRGZ0Lrw_5a945jVs\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember7289\">To test the repository, we will mimic the stages of Jenkins<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. Install Docker to a Ubuntu server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Install git on the server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Update the Docker Deamon to connect with the Nexus through insecure path<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7291\">&#8211; This is often necessary when using HTTP instead of HTTPS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7292\">&#8211; For production environments, it&#8217;s recommended to secure the Nexus instance with HTTPS to avoid using insecure registries.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\nsudo vi \/etc\/docker\/daemon.json\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> {\n\n    \"insecure-registries\" : [\"http:\/\/3.16.26.143:8091\"] \n\n    \/\/ \"insecure-registries\" : [\"Nexus_URL:Port_mentioned_for_Docker_Repo\"] \n\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7295\">&#8211; Restart the Docker Daemon<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl restart docker<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7296\">&#8211; verify the connectivity of client(Jenkins\/Docker) &amp; the Nexus<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker login -u admin 3.16.26.143:8091 <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7297\">&#8211; Enter the password set for the Nexus<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong> : Make sure to log out of Docker if the login test with the credentials are done to avoid potential security issues. sudo docker logout 3.16.26.143:8091<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">4. Clone a github repo (similar to Checkout stage for Jenkins during automation)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> sudo git clone https:\/\/github.com\/partho-dev\/sample-code.git<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Build the image (build stage as in Jenkins)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> sudo docker build -t 3.16.26.143:8091\/express .\n\n    sudo docker build -t 3.16.26.143:8091\/express:1.0 . \n\n# For Prod, its good to use version in auto increment<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7301\">&#8211; Verify if the image creation successfull<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo docker images <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6. Push the image to Nexus Repo (Push the image to Repo)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> sudo docker push 3.16.26.143:8091\/express<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">7. Verify if the Image gets uploaded into the Nexus Docker Repo<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media.licdn.com\/dms\/image\/v2\/D4D12AQEZZTw2-XAyBg\/article-inline_image-shrink_1500_2232\/article-inline_image-shrink_1500_2232\/0\/1724832115543?e=1732752000&amp;v=beta&amp;t=U8yyyG3MYpwGtrFwcBzJ6xYa1yfNJYB3C4Oqp2AmcSw\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Docker image is uploaded into the Nexus Private Repo<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ember7307\">The same above manual process can be automated by integrating Jenkins, and the declaritive pipeline can be somewhat like the below. I have added two more stages in that.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: groovy; title: ; notranslate\" title=\"\">\npipeline {\n    \n    agent any #Good to add some agent to execute the jobs\n    \n    environment {\n        imageName = &quot;Give_Image_Name&quot;\n        registryCredentials = &quot;admin&quot;\n        registry = &quot;3.16.26.143:8091&quot;\n        dockerImage = ''\n    }\n    \n    stages {\n        stage('checkout') {\n            steps {\n                git url: 'https:\/\/github.com\/partho-dev\/sample-code.git', branch: 'main'                  }\n        }\n    \n    \/\/ Docker images\n    stage('Docker image') {\n      steps{\n        script {\n          dockerImage = docker.build(imageName)\n        }\n      }\n    }\n\n    \/\/ Push the image from Jenkins to Nexus\n    stage('Push to Nexus') {\n     steps{  \n         script {\n            docker.withRegistry('http:\/\/' + registry, registryCredentials) {\n            dockerImage.push('latest')\n            \/\/or \n            \/\/dockerImage.push(&quot;${env.BUILD_NUMBER}&quot;)\n          }\n        }\n      }\n    }\n    \n    \/\/ Run the container - Stop the container if its running\n    stage('stop previous containers') {\n         steps {\n            sh 'docker ps -f name=container_name -q | xargs --no-run-if-empty docker container stop'\n            sh 'docker container ls -a -f name=container_name -q | xargs -r docker container rm'\n         }\n       }\n      \n    stage('Docker Run') {\n       steps{\n         script {\n                sh 'docker run -d -p 3000:3000 --rm --name container_name ' + registry + '\/' + imageName + ':latest'\n            }\n         }\n      }    \n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Nexus offers an efficient way to manage software artifacts, providing control over versioning, security, and access. Whether you&#8217;re working with Docker images, JAR files, or npm packages, Nexus can help you streamline the entire artifact management process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With its robust feature set, Nexus becomes an essential tool for enterprises looking to ensure secure and organized artifact storage. Pair it with tools like Jenkins and Docker, and you&#8217;ve got a powerful, automated CI\/CD pipeline.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 7<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span>3,450 In the world of DevOps, storing and managing artifacts\u2014whether they\u2019re Docker images, WAR files, or other build outputs\u2014is crucial for a smooth Continuous Integration\/Continuous Deployment (CI\/CD) pipeline. Public repositories<\/p>\n","protected":false},"author":1,"featured_media":5102,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"footnotes":""},"categories":[971],"tags":[],"class_list":["post-5075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create Private Repositories in Nexus? - Blog | Liainfraservices<\/title>\n<meta name=\"description\" content=\"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create Private Repositories in Nexus? - Blog | Liainfraservices\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog | Liainfraservices\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-27T04:57:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-25T07:27:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2240\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Partho\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Partho\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/\"},\"author\":{\"name\":\"Partho\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/person\\\/b5a729cb152dd3bc7f07550ca9d223e4\"},\"headline\":\"How to create Private Repositories in Nexus?\",\"datePublished\":\"2024-09-27T04:57:26+00:00\",\"dateModified\":\"2025-02-25T07:27:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/\"},\"wordCount\":1368,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Create-private-repositories-in-nexus.png\",\"articleSection\":[\"devops\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/\",\"name\":\"How to create Private Repositories in Nexus? - Blog | Liainfraservices\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Create-private-repositories-in-nexus.png\",\"datePublished\":\"2024-09-27T04:57:26+00:00\",\"dateModified\":\"2025-02-25T07:27:56+00:00\",\"description\":\"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Create-private-repositories-in-nexus.png\",\"contentUrl\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Create-private-repositories-in-nexus.png\",\"width\":2240,\"height\":1260,\"caption\":\"Create private repositories in nexus\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/how-to-create-private-repositories-in-nexus\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"devops\",\"item\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/category\\\/devops\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to create Private Repositories in Nexus?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\",\"name\":\"Blog | Liainfraservices\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#organization\",\"name\":\"Blog | Liainfraservices\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/lia-logo-b-e1635340384244.png\",\"contentUrl\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/10\\\/lia-logo-b-e1635340384244.png\",\"width\":308,\"height\":96,\"caption\":\"Blog | Liainfraservices\"},\"image\":{\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.liainfraservices.com\\\/blog\\\/#\\\/schema\\\/person\\\/b5a729cb152dd3bc7f07550ca9d223e4\",\"name\":\"Partho\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g\",\"caption\":\"Partho\"},\"description\":\"Partho Das, founder of Lia Infraservices, has 15+ years of expertise in cloud solutions, DevOps, and infrastructure security. He provides consultation on architecture planning, DevOps setup, Kubernetes, and cloud migrations. Partho holds multiple AWS and Azure certifications, along with CISCO CCNA &amp; CCNP. Connect on LinkedIn\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/partho-dev\\\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create Private Repositories in Nexus? - Blog | Liainfraservices","description":"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/","og_locale":"en_US","og_type":"article","og_title":"How to create Private Repositories in Nexus? - Blog | Liainfraservices","og_description":"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.","og_url":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/","og_site_name":"Blog | Liainfraservices","article_published_time":"2024-09-27T04:57:26+00:00","article_modified_time":"2025-02-25T07:27:56+00:00","og_image":[{"width":2240,"height":1260,"url":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png","type":"image\/png"}],"author":"Partho","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Partho","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#article","isPartOf":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/"},"author":{"name":"Partho","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/person\/b5a729cb152dd3bc7f07550ca9d223e4"},"headline":"How to create Private Repositories in Nexus?","datePublished":"2024-09-27T04:57:26+00:00","dateModified":"2025-02-25T07:27:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/"},"wordCount":1368,"commentCount":0,"publisher":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png","articleSection":["devops"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/","url":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/","name":"How to create Private Repositories in Nexus? - Blog | Liainfraservices","isPartOf":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#primaryimage"},"image":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#primaryimage"},"thumbnailUrl":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png","datePublished":"2024-09-27T04:57:26+00:00","dateModified":"2025-02-25T07:27:56+00:00","description":"Learn how to set up and manage private repositories for artifacts using Nexus. Explore repository types, security best practices, and step-by-step configuration on Ubuntu.","breadcrumb":{"@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#primaryimage","url":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png","contentUrl":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2024\/09\/Create-private-repositories-in-nexus.png","width":2240,"height":1260,"caption":"Create private repositories in nexus"},{"@type":"BreadcrumbList","@id":"https:\/\/www.liainfraservices.com\/blog\/how-to-create-private-repositories-in-nexus\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.liainfraservices.com\/blog\/"},{"@type":"ListItem","position":2,"name":"devops","item":"https:\/\/www.liainfraservices.com\/blog\/category\/devops\/"},{"@type":"ListItem","position":3,"name":"How to create Private Repositories in Nexus?"}]},{"@type":"WebSite","@id":"https:\/\/www.liainfraservices.com\/blog\/#website","url":"https:\/\/www.liainfraservices.com\/blog\/","name":"Blog | Liainfraservices","description":"","publisher":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.liainfraservices.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.liainfraservices.com\/blog\/#organization","name":"Blog | Liainfraservices","url":"https:\/\/www.liainfraservices.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2021\/10\/lia-logo-b-e1635340384244.png","contentUrl":"https:\/\/www.liainfraservices.com\/blog\/wp-content\/uploads\/2021\/10\/lia-logo-b-e1635340384244.png","width":308,"height":96,"caption":"Blog | Liainfraservices"},"image":{"@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.liainfraservices.com\/blog\/#\/schema\/person\/b5a729cb152dd3bc7f07550ca9d223e4","name":"Partho","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6c5fc8918cc5dbc844eccbeaaf854eef27d2c79ab17ff0022304f712805d6959?s=96&d=mm&r=g","caption":"Partho"},"description":"Partho Das, founder of Lia Infraservices, has 15+ years of expertise in cloud solutions, DevOps, and infrastructure security. He provides consultation on architecture planning, DevOps setup, Kubernetes, and cloud migrations. Partho holds multiple AWS and Azure certifications, along with CISCO CCNA &amp; CCNP. Connect on LinkedIn","sameAs":["https:\/\/www.linkedin.com\/in\/partho-dev\/"]}]}},"_links":{"self":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/comments?post=5075"}],"version-history":[{"count":19,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5075\/revisions"}],"predecessor-version":[{"id":5108,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/posts\/5075\/revisions\/5108"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/media\/5102"}],"wp:attachment":[{"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/media?parent=5075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/categories?post=5075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liainfraservices.com\/blog\/wp-json\/wp\/v2\/tags?post=5075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}